r中两行之间的阴影区域 [英] shading area between two lines in r
本文介绍了r中两行之间的阴影区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,如果我需要在情节中阴影两个区域
For example if i need to shade two area in plot
x<-rep(1:10)
plot(x,type="h")
作为示例,我需要将区域从1到3以及从7到10进行着色,
I need as an example shade the area from 1 to 3 and from 7 to 10,
我使用此命令,但省略了绘图行.
I use this commands but it omitted the lines of plot.
usr <- par('usr')
rect(1, usr[3], 3, usr[4], col='green')
推荐答案
如果我对您的理解正确,那么可以使用鲜为人知的plot.default()
自变量plot.default()
来获得所需的内容:
If I understand you correctly, you can get what you want by using the little-known panel.first=
argument to plot.default()
:
plot(x,type="h",
panel.first = {
usr <- par('usr')
rect(c(1,7), usr[3], c(3,10), usr[4], col='green', border=NA)
})
或者,为避免与par('usr')
值混为一谈,只需执行以下操作:
Or, to avoid any mucking around with par('usr')
values, just do:
plot(x, type="h",
panel.first = rect(c(1,7), -1e6, c(3,10), 1e6, col='green', border=NA))
这篇关于r中两行之间的阴影区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文