【发布时间】:2017-07-11 23:07:09
【问题描述】:
我正在尝试在 fill.contour 顶部放置一个线图,以实现与图 1 here 中描述的效果相似的效果。
require("lattice")
require("latticeExtra")
mat = matrix(c(1:9),nrow=3,byrow=TRUE); time = c(1:3); mid = c(1:3)
mat
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 7 8 9
line = colMeans(mat)
shades = colorRampPalette(c("red", "green"))
filled.contour(mid,time,t(apply(mat,2,rev)),
zlim=c(1,9),nlevels=9,col=shades(9))
xyplot(line~time,type="l")
最明显的方法是使用图层,但到目前为止它对我没有用。
layer(filled.contour(mid,time,t(apply(mat,2,rev)),
zlim=c(1,9),nlevels=9,col=shades(9))) +
layer(xyplot(line~time,type="l"))
有什么建议吗?
【问题讨论】:
-
我会在绘制第二个图之前尝试使用
par(new=TRUE),但我不使用lattice,所以我不知道它是否适合你。 -
函数filled.contour 实际上不是lattice 或latticeExtra 包的一部分。它是base R 图形的一部分。它不能与作为 lattice 和 latticeExtra 一部分的 xyplot 或 layer 函数一起使用。