如何使点大小独立于格子绘图中的分组

时间:2015-04-09 14:59:14

标签: r plot lattice

假设我想使用xyplot制作一系列不同大小的点图,如:

> xyplot(1:6 ~ 1:6, cex = 1:6)

情节就像

f1

但是当我在图中添加组时,每个组中点的大小是同质的。

> g <- c('A', 'A', 'B', 'B', 'C', 'C')
> xyplot(1:6 ~ 1:6, groups = g, cex = 1:6)

f2

此外,如果我使用|进行分组,那么在每个方面,点的大小将再次从cex

中的第一个值开始
> xyplot(1:6 ~ 1:6 | g, cex = 1:6)

f3

那么有什么解决方案可以使cex独立于groups|,例如在groups示例中我希望看到类似于第一个只有色差的情节。

1 个答案:

答案 0 :(得分:3)

这很有效:

library(lattice)    
g <- c('A', 'A', 'B', 'B', 'C', 'C')

xyplot(1:6 ~ 1:6, groups = g,
       panel=function(x,y,subscripts,...) {
       panel.superpose(x,y,subscripts,...,
         panel.groups=function(x,y,subscripts,group.number,...){
               panel.xyplot(x,y,cex=subscripts,col=group.number)}
       )
    }
)

subscripts跟踪整个数据集的索引(对于点大小)和group.number组的索引(对于颜色)。