【问题标题】:Conditional Background of a plot in RR中绘图的条件背景
【发布时间】:2014-10-10 09:06:44
【问题描述】:

我只想知道如何制作这种有条件的彩色背景。条件可能由这个时间序列或另一个计算。 例如,我有两个时间序列。当第一个值为正时,第二个图的背景值为绿色,否则为红色。

【问题讨论】:

标签: r graphics plot background


【解决方案1】:

这是一种方法的示例。

x <- 1:100
t1 <- rnorm(100)
t2 <- rnorm(100)
plot(x, t2, type="n")
abline(v=x, col=c("red", "green")[(t2>0)+1])
lines(x, t1)

【讨论】:

    【解决方案2】:

    rasterImage 可能是正确的工具,

    x <- seq(0,10,length=30)
    y <- jitter(sin(x),a=0.1)
    grad <- scales::rescale(y^2, to = c(0.5,0.1))
    plot(x, y, type="n", xaxs="i", yaxs="i")
    rasterImage(t(hsv(h = grad, s = 1, v = 0.8)), 
                xleft = min(x), ybottom = min(y),
                xright = max(x), ytop = max(y))
    lines(x,y)
    

    【讨论】:

      猜你喜欢
      • 2012-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-26
      • 1970-01-01
      • 1970-01-01
      • 2021-01-28
      • 2012-02-28
      相关资源
      最近更新 更多