使用 ggplot2 添加虚线

Add dashed line with ggplot2

我无法使 WBank 线变成虚线,而且它在图例中也显示为虚线。这是我到目前为止写的:

ggplot(data = Differences_TODO, aes(x = Years,y= MeanDifference))+geom_line(aes(color=region)) +
  labs(x = "Figure 2 (Modified) - Extra hours to get to work in Israel by region of residence" , y = "Extra Hours")+
  theme_bw() + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),legend.position = c(0.2,0.8))+
  scale_x_continuous(n.breaks = 10) + 
  scale_linetype_manual(values=c("solid","dotted")) +
  theme(legend.title=element_blank()) +
  scale_color_manual(values = c("black", "black"))

我不明白为什么 scale_linetype_manual 不能正常工作。 这是我的图表目前的样子:

感谢菲尔的帮助,正确的代码应该包括geom_line(aes(linetype=region))