如何突出显示绘图上的时间范围?
我随时间采样了一些信号,我使用连续线在 R 中绘制了这些信号。此外,我想强调图中的几个特定时间范围。
我当前的方法是绘制具有适当宽度和水平位置的全高透明矩形,与时间范围相匹配。我认为这是一个很好的表示,因为它清楚地将范围内的点与范围外的点分开;但还有更好的吗?
问题的第二个实际部分。现在我正在绘制这样的信号:
p <- ggplot(data=gs, mapping=aes(x=frameno, y=value, col=variable)) +
geom_line()
p
我尝试手动绘制一个 alpha 混合矩形:
p + geom_rect(aes(xmin=600, xmax=650, ymin=-3, ymax=3),
colour=alpha("grey20", 0.5), fill.alpha=0.5)
- 但到目前为止没有成功。有什么提示吗?
I have a few signals sampled over time which I plot in R using continuous lines. Additionally, I would like to highlight several specific time ranges on the plot.
My current approach is to draw full-height transparent rectangles with appropriate width and horizontal position which match the time range. I think this is a good representation, as it clearly separates points inside the range from those outside of it; but are there better ones?
And the second, practical part of the question. Now I'm plotting the signals like this:
p <- ggplot(data=gs, mapping=aes(x=frameno, y=value, col=variable)) +
geom_line()
p
I have tried to draw an alpha blended rectangle manually:
p + geom_rect(aes(xmin=600, xmax=650, ymin=-3, ymax=3),
colour=alpha("grey20", 0.5), fill.alpha=0.5)
— but no success so far. Any hints?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为绘制矩形工作正常,我不知道更好的解决方案,如果一条或多条简单的垂直线是不够。
只需使用
alpha=0.5
而不是fill.alpha=0.5
来解决透明度问题,同时在geom_rect 中指定
。例如,根据钻石数据绘制图表:inherit.aes = FALSE
()另请注意
ymin
和ymax
可以轻松设置为-Inf
和Inf
。I think drawing rectangles just work fine, I have no idea about better solution, if a simple vertical line or lines are not enough.
And just use
alpha=0.5
instead offill.alpha=0.5
for the transparency issue also specifyinginherit.aes = FALSE
ingeom_rect()
. E.g. making a plot from the diamonds data:Also note that
ymin
andymax
could be set to-Inf
andInf
with ease.