scale_linetype_manual not working

i'm trying to change the linetypes in my plot. This is what i've tried but it's not working.. Thank you!

p<- Counterfactual %>% 
  ggplot(aes(x=Date, y = Guests, color = City)) +
  geom_line() +
  scale_y_continuous(limits = c(1000000,3000000)) +
  theme_classic() +
  labs(title = "Recap",
       x="Time", y="Guests") + 
  theme(plot.title = element_text(hjust=0.5)) +
  theme(legend.justification=c(1,0), legend.position = c(1,0))+
                              'black','darkcyan','darkgreen','blue')) +

p + geom_vline(xintercept=as.numeric(Counterfactual$Date[31]),

You must map a column in your data to the linetype aesthetic and then assign linetypes to the values of that column. You do not have to use a named vector as I did but it makes the intention of the code much clearer. Notice that your color worked because the aes includes color = City. Here is an example using mtcars.

LINES <- c("4" = "solid", "6" = "dotted", "8" = "solid")
ggplot(mtcars, aes(x = disp, y = mpg, linetype = factor(cyl))) + 
  geom_line() +
  scale_linetype_manual(values = LINES)

Created on 2020-06-17 by the reprex package (v0.3.0)

thank you so much! Helped a lot

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.