突出显示R中图表的特定范围

时间:2015-06-22 15:05:55

标签: r graph highlight

library(season)
plot(CVD$yrmon, CVD$cvd, type = 'o',pch = 19,ylab = 'Number of CVD deaths per month',xlab = 'Time')

如果我想基于x值突出显示图表的区域,请参阅1994-1998我该怎么做?

任何想法都会受到赞赏 感谢。

2 个答案:

答案 0 :(得分:2)

或者您可以在感兴趣的区域放置一个矩形:

rect(xleft=1994,xright = 1998,ybottom=range(CVD$cvd)[1],ytop=range(CVD$cvd)[2], density=10, col = "blue")

Maybe something like this

答案 1 :(得分:0)

您可以为该范围内的点着色另一种颜色

plot(CVD$yrmon, CVD$cvd, type = 'o',pch = 19,ylab = 'Number of CVD deaths per month',xlab = 'Time')
points(cvd ~ yrmon, type="o", pch=19, col="red", 
       data=CVD[CVD$yrmon >= 1994 & CVD$yrmon <= 1998,])

enter image description here