【问题标题】:Highlighting specific ranges on a Graph in R在 R 中突出显示图表上的特定范围
【发布时间】:2015-09-08 02:39:37
【问题描述】:
library(season)
plot(CVD$yrmon, CVD$cvd, type = 'o',pch = 19,ylab = 'Number of CVD deaths per month',xlab = 'Time')

如果我想根据 x 值突出显示 1994-1998 年的图形区域,我该怎么做?

任何想法将不胜感激 谢谢。

【问题讨论】:

    标签: r graph highlight


    【解决方案1】:

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

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

    【讨论】:

    • 您可能希望 rect 覆盖整个 y 范围 .. rect(xleft=1994,xright = 1998,ybottom=par("usr")[3], ytop=par("usr")[4], density=10, col = "blue")see here
    【解决方案2】:

    您可以将该范围内的点涂上另一种颜色,

    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,])
    

    【讨论】:

    • 我试过了,但是所有的点都变成了红色。也许我输入错了?
    猜你喜欢
    • 2022-06-14
    • 2010-10-04
    • 1970-01-01
    • 1970-01-01
    • 2012-01-06
    • 1970-01-01
    • 2014-08-26
    • 2010-12-27
    • 1970-01-01
    相关资源
    最近更新 更多