[英]How to overlay a line plot on top of a filled.contour?
I'm trying to put a line plot on top of a filled.contour to achieve a similar effect to the one depicted in Figure 1 here . 我正在尝试在fill.contour顶部放置一个折线图,以实现与此处图1所示类似的效果。
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")
The most obvious way to go is using layers, but it hasn't worked for me so far. 最明显的方法是使用图层,但是到目前为止,它对我没有用。
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"))
Any suggestions? 有什么建议么?
Looking at the help page for filled.contour
, you may read under "Note": If you want to annotate the main contour plot, for example to add points, you can specify graphics commands in the plot.axes argument. 查看
filled.contour
的帮助页面,您可以在“注意”下阅读: 如果要注释主轮廓图,例如添加点,则可以在plot.axes参数中指定图形命令。
### your code
require("lattice")
require("latticeExtra")
mat = matrix(c(1:9),nrow=3,byrow=TRUE)
time = c(1:3)
mid = c(1:3)
line = colMeans(mat)
shades = colorRampPalette(c("red", "green"))
### call to filled.contour with plot.axes{} for some line
filled.contour(mid, time, t(apply(mat, 2, rev)),
zlim = c(1, 9), nlevels = 9, col = shades(9),
plot.axes = { axis(1); axis(2); lines(c(1.5,2, 2.5), c(2,2.8, 2.8), col = "white") }
)
The code yields this plot: 该代码产生以下图:
You could also plot the relation between your objects line
and time
with the following code. 您还可以使用以下代码绘制对象
line
与time
之间的关系。 Remark that I had to substract 3
from line
to make it fit in the graph: 请注意,我必须从
line
减去3
才能使其适合图形:
filled.contour(mid, time, t(apply(mat, 2, rev)),
zlim = c(1, 9), nlevels = 9, col = shades(9),
plot.axes = { axis(1); axis(2); lines(line-3, time, col = "white") }
)
yielding the graph below: 产生下图:
Please let me know whether this is what you want. 请让我知道这是否是您想要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.