【问题标题】:Add dashed line with ggplot2用 ggplot2 添加虚线
【发布时间】:2021-07-09 17:38:22
【问题描述】:

我无法将 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))
  • 谢谢!效果很好

标签: r dataframe rbind


【解决方案1】:

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

【讨论】:

  • 请添加更多详细信息以扩展您的答案,例如工作代码或文档引用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多