在lattice面板中合并或叠加xy图

11
尝试弄清楚如何在创建后向现有的Lattice面板添加点或数据系列。 这是否与plot.points和/或update函数有关?
尝试弄清楚如何在创建后向现有的Lattice面板添加点或数据系列。 这是否与plot.points和/或update函数有关?
# Initialize first plot
library(lattice)
a <- xyplot(Sepal.Length~Sepal.Width, groups=Species, data=iris
            , subset=Species %in% levels(Species)[1:2])
print(a) 

# Create second plot to overlay or merge with the first plot
b <- xyplot(Sepal.Length~Sepal.Width, groups=Species, data=iris
            , subset=Species %in% levels(Species)[3])

# Initial attempt at merging plots:
library(latticeExtra)
print(c(a,b)) # this displays the data in an adjacent second panel
print(c(a,b,layout=c(1,1))) # and this only shows series "b"

注意:在此示例中,“a”和“b”两个图都来自原始的iris数据帧,但理想情况下,解决方案应该适用于不同的数据帧。

有什么想法吗? 谢谢!
Bryan

1个回答

20
你正在寻找as.layer,我认为;尝试这个。它也在latticeExtra库中。

你正在寻找as.layer,我认为;尝试这个。它也在latticeExtra库中。

library(latticeExtra)
a + as.layer(b)

文档请参阅此处:http://latticeextra.r-forge.r-project.org/#as.layer


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接