# Clean Sector employment tracking file
# From Rstudio, click file -> import dataset -> from excel.
# Name file, "neo_employ" and change title of plot and graph at end for industry.
library(readxl)
neo_employ <- read_excel("C:/Users/ALogar/Team Neo/Research Department - 2023 Research Requests/QCEW for KPI/Q4 2022 industry 51 data national/51.xlsx")
# Double-check if excel transformed into data.frame
class(neo_employ)
# Make new dataframe for only data we need
neo_employ <- subset(neo_employ, select = c(area_fips, own_code, industry_code, year, qtr, qtrly_estabs, month1_emplvl, month2_emplvl, month3_emplvl, total_qtrly_wages))
# Filter to only rows for NEO
# Call tidyverse library
library(tidyverse)
library(dplyr)
neo_employ <- filter(neo_employ, area_fips %in% c("39005", "39007", "39029", "39035", "39043", "39055", "39077", "39085", "39093", "39099", "39103", "39133", "39139", "39151", "39153", "39155", "39157", "39169"))
# Add column to link FIPS and county name
neo_employ <-
neo_employ %>%
mutate(
county = case_when(
str_detect(area_fips, "39005") ~ "Ashland",
str_detect(area_fips, "39007") ~ "Ashtabula",
str_detect(area_fips, "39029") ~ "Columbiana",
str_detect(area_fips, "39035") ~ "Cuyahoga",
str_detect(area_fips, "39043") ~ "Erie",
str_detect(area_fips, "39055") ~ "Geauga",
str_detect(area_fips, "39077") ~ "Huron",
str_detect(area_fips, "39085") ~ "Lake",
str_detect(area_fips, "39093") ~ "Lorain",
str_detect(area_fips, "39099") ~ "Mahoning",
str_detect(area_fips, "39103") ~ "Medina",
str_detect(area_fips, "39133") ~ "Portage",
str_detect(area_fips, "39139") ~ "Richland",
str_detect(area_fips, "39151") ~ "Stark",
str_detect(area_fips, "39153") ~ "Summit",
str_detect(area_fips, "39155") ~ "Trumbull",
str_detect(area_fips, "39157") ~ "Tuscarawas",
str_detect(area_fips, "39169") ~ "Wayne"
))
# Rearrange columns function
neo_employ <- neo_employ %>% relocate(county)
# Sum up each row for NEO
neo_employ <- summarize(neo_employ,
month1_emplvl = sum(month1_emplvl),
month2_emplvl = sum(month2_emplvl),
month3_emplvl = sum(month3_emplvl),
industry_code = "51",
qtrly_estabs = sum(qtrly_estabs),
total_qtrly_wages = sum(total_qtrly_wages))
# Use pivotlonger for reshaping this data to plot
neo_employ <- pivot_longer(neo_employ, cols = starts_with("month") , names_to = "month", values_to = "emp_lvl")
library(ggplot2)
plot_51 <- ggplot(neo_employ, aes(x = month, y = emp_lvl, group = 1)) +
geom_point() +
geom_line() +
ggtitle("Information Sector Total Employment in NEO, Qtr 4 2022") +
xlab("Month") + ylab("Number of Employees")
plot(plot_51)
install.packages("xlsx")
library("xlsx")
write_excel_csv(neo_employ, file = "myworkbook.csv",
append = FALSE)
```