Can we add shadows to (dashed) lines in R (ggplot2)?

旧时模样 提交于 2019-12-11 02:26:10

问题


I was asked to add shadows to a dashed-line in R. It would be similar to this image I found on-line, except it is for non-solid lines:

I did not find any specific control/package for this purpose. If it was a solid line that I needed a shadow for, I would have simulated the shadow using another line with different opacity and thickness. But it seems for the non-solid lines (dashed, dotted, etc) this workaround won't work, since their gaps won't match as you change the thickness.

Any ideas?


Image is copied from here only for the sake of clarity.


回答1:


You can only tweak this like

df <- data.frame(x = 1:20, y = cumsum(rnorm(20)))
ggplot(df, aes(x = x, y = y)) +
  geom_line(aes(x = x+0.15, y = y-0.15), alpha = 0.2, lwd = 1.2, linetype = 2) +
  geom_point(aes(x = x+0.15, y = y-0.15), alpha = 0.1, size = 2.5) +
  geom_line(lwd = 1, linetype = 2) + 
  geom_point(size = 2.5) +
  theme_bw()



来源:https://stackoverflow.com/questions/49861489/can-we-add-shadows-to-dashed-lines-in-r-ggplot2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!