Michael Kubovy
2008-May-18 03:03 UTC
[R] How to change col and pch between panels in xyplot
Dear R-helpers, x <- rep(1:2, 4) y <- c(2, 4, 3, 5, 1, 3, 2, 4) w <- factor(rep(1:2, each = 4)) v <- rep(1:2, each = 2, 2) xyplot(y ~ x | w, groups = v, type = 'b') How do I tell xyplot to use four colors and four plot characters and four line types? And how do I set up an appropriate key in each? _____________________________ Professor Michael Kubovy University of Virginia Department of Psychology USPS: P.O.Box 400400 Charlottesville, VA 22904-4400 Parcels: Room 102 Gilmer Hall McCormick Road Charlottesville, VA 22903 Office: B011 +1-434-982-4729 Lab: B019 +1-434-982-4751 Fax: +1-434-982-4766 WWW: http://www.people.virginia.edu/~mk9y/ [[alternative HTML version deleted]]
hadley wickham
2008-May-18 03:50 UTC
[R] How to change col and pch between panels in xyplot
On Sat, May 17, 2008 at 10:03 PM, Michael Kubovy <kubovy at virginia.edu> wrote:> Dear R-helpers, > > x <- rep(1:2, 4) > y <- c(2, 4, 3, 5, 1, 3, 2, 4) > w <- factor(rep(1:2, each = 4)) > v <- rep(1:2, each = 2, 2) > xyplot(y ~ x | w, groups = v, type = 'b') > > How do I tell xyplot to use four colors and four plot characters and > four line types? And how do I set up an appropriate key in each?Maybe (if I understand you correctly) xyplot(y ~ x | w, groups = interaction(v, w), type = 'b', auto.key = TRUE) Or in ggplot2 group <- interaction(v, w) qplot(x, y, facets = . ~ v, geom=c("point","line"), colour=group, shape=group, linetype=group) although there appears to be a bug in the legend which I need to fix. Hadley -- http://had.co.nz/