Reputation: 765
Say I want to make a plot of a series of points and of different size, using xyplot
like:
> xyplot(1:6 ~ 1:6, cex = 1:6)
And the plot comes like
But when I add groups to the plot, the sizes of the points are homogenous within each group.
> g <- c('A', 'A', 'B', 'B', 'C', 'C')
> xyplot(1:6 ~ 1:6, groups = g, cex = 1:6)
Also, if I use |
to group, it comes that in each facet the size of the points goes again from the first value in the cex
> xyplot(1:6 ~ 1:6 | g, cex = 1:6)
So is there any solution that I could make the cex
independent from groups
and |
, for example in the groups
example I hope to see a plot like the first plot with color difference only.
Upvotes: 4
Views: 547
Reputation: 1297
Well this works:
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
keeps track of the index of the whole data set (for point size) and group.number
the index of the groups (for color).
Upvotes: 5