There are a lot of posts on geom_line() but I haven't found a question specific to me needs. I'm using the data as in the post here: Using `geom_line()` with X axis being factors for a simple example. but adding is more dates for a different year (2018). Here's the data:
hist <- data.frame(date=Sys.Date() + 0:06,
counts=1:7)
hist2 <- data.frame(date=Sys.Date() - 365 + 0:06,
counts=1:7)
histdf <- rbind(hist, hist2)
histdf <- transform(histdf, weekday=factor(weekdays(date),
levels=c('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')))
gsub("-.*","",histdf$date) -> histdf$year #because I just want the year for now
Using dplyr to group, here's a plot connecting all points for each year:
histdf %>%
group_by(year) %>%
ggplot() +
geom_line(aes(x = weekday, y = counts, color=year, group=year))
I what though is connect specific days of the week for each year by different line types. So connecting M/T/W/F with a solid red line for 2018 and blue for 2019. Then a dashed line red line for TH/S/S in 2018 and blue for 2019.
Thanks very much for any help.