假设我想使用xyplot
制作一系列不同大小的点图,如:
> xyplot(1:6 ~ 1:6, cex = 1:6)
情节就像
但是当我在图中添加组时,每个组中点的大小是同质的。
> g <- c('A', 'A', 'B', 'B', 'C', 'C')
> xyplot(1:6 ~ 1:6, groups = g, cex = 1:6)
此外,如果我使用|
进行分组,那么在每个方面,点的大小将再次从cex
> xyplot(1:6 ~ 1:6 | g, cex = 1:6)
那么有什么解决方案可以使cex
独立于groups
和|
,例如在groups
示例中我希望看到类似于第一个只有色差的情节。
答案 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
组的索引(对于颜色)。