首页 > 解决方案 > 用 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 不能正常工作。这是我的图表目前的样子: 图形

标签: rdataframerbind

解决方案


Thanks to Phil for helping out, the correct code should include geom_line(aes(linetype=region))


推荐阅读