gpt4 book ai didi

r - r中两条线之间的阴影区域

转载 作者:行者123 更新时间:2023-12-03 23:33:49 33 4
gpt4 key购买 nike

例如,如果我需要在绘图中为两个区域着色

x<-rep(1:10)
plot(x,type="h")

作为示例,我需要将区域从 1 到 3 和从 7 到 10,

我使用这个命令,但它省略了绘图线。
usr <- par('usr')
rect(1, usr[3], 3, usr[4], col='green')

最佳答案

如果我理解正确,您可以使用鲜为人知的panel.first= 得到您想要的东西。论据 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')值,只需执行以下操作:
plot(x, type="h", 
panel.first = rect(c(1,7), -1e6, c(3,10), 1e6, col='green', border=NA))

enter image description here

关于r - r中两条线之间的阴影区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23351752/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com