2017-09-14 46 views
2

我想用线条绘制xyplot。举个例子,我使用虹膜数据,我知道实际的情节并没有真正意义:)R-package格子:使用面板参数时,按颜色不起作用

library(lattice) 

panel.iris <- function(x,y){ 
    panel.xyplot(x,y) 
    panel.lines(x,y) 
    } 

xyplot(Sepal.Length ~ Sepal.Width| Petal.Width, data = iris, groups= Species, 
auto.key=list(space="right"), panel=panel.iris) 

这给了我如下图所示: Iris xy plot with lines but without color by group 但其实我希望它由着色组,像这样(但增加了行): Iris xy plot colored by group but without lines 我只能实现这一点,当我不使用面板参数......有没有解决这个问题的方法?

非常感谢!

回答

0

您需要在groupssubscripts传递给panel.xyplot功能,使其了解与每个点去什么颜色,像这样:

panel.iris <- function(x,y,groups,subscripts){ 
    panel.xyplot(x,y,groups=groups, subscripts=subscripts) 
    panel.lines (x,y) 
}