在 R 中突出显示图形上的特定范围
Highlighting specific ranges on a Graph in R
library(season)
plot(CVD$yrmon, CVD$cvd, type = 'o',pch = 19,ylab = 'Number of CVD deaths per month',xlab = 'Time')
如果我想根据 1994-1998 年的 x 值突出显示图形区域,我该怎么做?
如有任何想法,我们将不胜感激
谢谢
您可以将该范围内的点涂成另一种颜色,
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,])
或者您可以在感兴趣的区域上放置一个矩形:
rect(xleft=1994,xright = 1998,ybottom=range(CVD$cvd)[1],ytop=range(CVD$cvd)[2], density=10, col = "blue")
library(season)
plot(CVD$yrmon, CVD$cvd, type = 'o',pch = 19,ylab = 'Number of CVD deaths per month',xlab = 'Time')
如果我想根据 1994-1998 年的 x 值突出显示图形区域,我该怎么做?
如有任何想法,我们将不胜感激 谢谢
您可以将该范围内的点涂成另一种颜色,
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,])
或者您可以在感兴趣的区域上放置一个矩形:
rect(xleft=1994,xright = 1998,ybottom=range(CVD$cvd)[1],ytop=range(CVD$cvd)[2], density=10, col = "blue")