The task at hand is to have all 17 counties charted at the same time in R. Hopefully, each line would be a different color. I know how to produce a single line chart for a single county. The question is how to get all 17 to show on one line chart in R.
Some background. The dataset that this is drawn from has all 17 counties and a statewide value in it. A small sample is below
type area year periodtype period unemprate
04 000003 2020 03 01 4.2
04 000003 2020 03 02 4.3
04 000005 2020 03 01 4.6
04 000005 2020 03 02 4.7
04 000007 2020 03 01 4.9
04 000007 2020 03 02 5.6
This is the code that I have been using for creating the single line chart
First, this creates the data frame
labforce1m <- dbGetQuery(connection, "SELECT area,year,period,unemprate FROM labforce")
Second, this creates the date since this does not exist in the data
labforce1m$date<- ymd(paste(labforce1m$year,labforce1m$period,"1",sep="-"))
Third, to produce the chart
Countyxyz %>%
Filter (area == '000003')
ggplot(data=labforce1m, aes(x=date, y=unemprate))+geom_line()
I know that the following will do the required task but all lines will be the same color
ggplot(data=labforce1m, aes(x=date, y=unemprate, group =
area))+geom_line()
My intuition is that I have to use a loop but nothing that I have read online is simple enough to retrofit to my simple example.