【发布时间】:2014-10-10 09:06:44
【问题描述】:
我只想知道如何制作这种有条件的彩色背景。条件可能由这个时间序列或另一个计算。 例如,我有两个时间序列。当第一个值为正时,第二个图的背景值为绿色,否则为红色。
【问题讨论】:
标签: r graphics plot background
我只想知道如何制作这种有条件的彩色背景。条件可能由这个时间序列或另一个计算。 例如,我有两个时间序列。当第一个值为正时,第二个图的背景值为绿色,否则为红色。
【问题讨论】:
标签: r graphics plot background
这是一种方法的示例。
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)
【讨论】:
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)
【讨论】: