xyplot时间序列,其中绿色为正值,红色为负值,以R为单位 [英] xyplot time series with positive values in green, negative in red, in R
本文介绍了xyplot时间序列,其中绿色为正值,红色为负值,以R为单位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面的(简化的)时间序列图中,是否有一种巧妙的方法可以使用lattice::xyplot
将负值着色为红色,将其他负值着色为绿色?
Is there a neat way to color negative values in red and others in green for a (simplified) time series plot below, using lattice::xyplot
?
set.seed(0)
xyplot(zoo(cumsum(rnorm(100))), grid=T)
推荐答案
格子基于grid
,因此您可以使用网格的裁剪功能
Lattice is based on grid
so you can use grid's clipping functionality
library(lattice)
library(grid)
set.seed(0)
x <- zoo(cumsum(rnorm(100)))
xyplot(x, grid=TRUE, panel = function(x, y, ...){
panel.xyplot(x, y, col="red", ...)
grid.clip(y=unit(0,"native"),just=c("bottom"))
panel.xyplot(x, y, col="green", ...) })
这篇关于xyplot时间序列,其中绿色为正值,红色为负值,以R为单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文