Take the following simple graph of two time series from a dataset economics{ggplot2}
require(dplyr)
require(ggplot2)
require(lubridate)
require(tidyr)
economics %>%
gather(indicator, percentage, c(4:5), -c(1:3, 6)) %>%
mutate(Y2K = year(date) >= 2000) %>%
group_by(indicator, Y2K) %>%
ggplot(aes(date, percentage, group = indicator, colour = indicator)) + geom_line(size=1)

I would like to change linetypefrom “solid” to “dotted” (and possibly also strings size) for all points of the 21st century, i.e. for those observations for which it Y2Kis equal TRUE.
I did group_by(indicator, Y2K), but inside the command ggplotit appears, I can’t use group =at several levels, so now the properties of the line differ only by indicator.
Question . How can I achieve this segmental appearance?
UPDATE : my preferred solution is a little tweak from the @sahoang file:
economics %>%
gather(indicator, percentage, c(4:5), -c(1:3, 6)) %>%
ggplot(aes(date, percentage, colour = indicator)) +
geom_line(size=1, aes(linetype = year(date) >= 2000)) +
scale_linetype(guide = F)
group_by, @Roland, filter , Y2K ( , , ).