I am trying to make a plot where each level of a factor gets its own series. While I am a long time user of R I am not up with some of the latest improvements. For example I have not yet learned ggplot which figures in some related questions but I cannot yet translate what I want to do into ggplot. Here is a simple example:
#library(tidyverse) # uncomment if not loaded
in_data <- read_csv("http://www.nfgarland.ca/National_Custom_Data.csv")
in_data <- in_data %>%
mutate(Tot = in_data$`NUM INFLUENZA DEATHS`+in_data$`NUM PNEUMONIA DEATHS`) %>%
arrange(SEASON) %>%
mutate(SEASON = factor(SEASON,ordered=TRUE))
filter(in_data,SEASON == "2015-16")$Tot %>% plot((1:length(.)),
.,
type = "l",
col = "red",
xlab ="Flu Season Week",
ylab = "Deaths",
ylim = c(2000,7500))
filter(in_data,SEASON == "2016-17")$Tot %>% lines((1:length(.)),., col="orange")
filter(in_data,SEASON == "2017-18")$Tot %>% lines((1:length(.)),. ,col="blue")
filter(in_data,SEASON == "2018-19")$Tot %>% lines((1:length(.)),. ,col="green")
filter(in_data,SEASON == "2019-20")$Tot %>% lines((1:length(.)),., ,col="black")
` As you can see I have learned a number of tidyverse concepts and this code works fine. But I assume there really ought to be a way to do this automagically in the tidyverse without defining each and every lines() separately, I would think, and I cannot identify it. I do know how to handle palettes, so the color changes are no problem. Note also that while there are 52 weeks of data for previous seasons, in this file there are only 24 weeks gone in the present flu season year.


