我们可以在R(ggplot2)中的虚线上添加阴影吗? [英] Can we add shadows to (dashed) lines in R (ggplot2)?

查看:150
本文介绍了我们可以在R(ggplot2)中的虚线上添加阴影吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求在R中的虚线上添加阴影。它类似于我在网上找到的这张图片,不同的是它是用于非实线的:

b



我没有为此目的找到任何特定的控件/包。如果这是一条我需要阴影的实线,那么我会使用另一条具有不同不透明度和厚度的线来模拟阴影。但是对于非实线(虚线,点线等)来说,这种解决方法似乎行不通,因为当您更改厚度时,它们的间隙将不匹配。



有任何想法吗?






图片是从


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.

解决方案

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()

这篇关于我们可以在R(ggplot2)中的虚线上添加阴影吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆