[R] Lattice: Customizing point-sizes with groups
Paul Boutros
paul.boutros at utoronto.ca
Tue Mar 10 02:49:42 CET 2009
Hello,
I am creating a scatter-plot in lattice, and I would like to customize
the size of each point so that some points are larger and others
smaller. Here's a toy example:
library(lattice);
temp <- data.frame(
x = 1:10,
y = 1:10,
cex = rep( c(1,3), 5),
groups = c( rep("A", 5), rep("B", 5) )
);
xyplot(y ~ x, temp, cex = temp$cex, pch = 19);
This works just fine if I create a straight xy-plot, without groups.
However when I introduce groupings the cex argument specifies the
point-size for the entire group. For example:
xyplot(y ~ x, temp, cex = temp$cex, pch = 19, group = groups);
Is it possible to combine per-spot sizing with groups in some way?
One work-around is to manually specify all graphical parameters, but I
thought there might be a better way than this:
temp$col <- rep("blue", 10);
temp$col[temp$groups == "B"] <- "red";
xyplot(y ~ x, temp, cex = temp$cex, pch = 19, col = temp$col);
Any suggestions/advice is much appreciated!
Paul
More information about the R-help
mailing list