I would like to use lattice graphics to plot multiple functions (or groups
or subpopulations) on the same plot region, using different line types "lty"
or colors "col" to distinguish the functions (or groups).

In traditional graphics, this seems straightforward: First plot all the data
using 'type="n"', and subsequently execute a series of "points" or "lines"
commands, one for each different group or function.

What is the elegant way to do this using xyplot?

To make this concrete, consider the following toy example:

k<- 10
x<- (1:k)/3
yM<-6 + x^2
yF<-12 + x^(1.5)
xNA<-x[length(x)]

# Insertion of NA row is necessary to prevent a meaningless line
# from being drawn from the females to the males across the entire plot.

DAT<-data.frame(
x=c(x, xNA, x)
,
y=c(yF, NA, yM)
,
sex=c( rep(0, k ), 0,  rep(1, k))
)

library("lattice")

xyplot(
y ~ x
, data=DAT
, type="l"
)

This draws both men and women in the same color and line type. Instead, I
want to specify different "col" and "lty" values for the two groups.

More generally, does a reference exist that explains this kind of thing,
with examples? I have not yet found an answer to this question in Paul
Murrell's book. Does Deepayan Sarkar's _Lattice_ go into that kind of
detail?

(I use lattice, not traditional graphics, because the plot will eventually
be conditioned on a third categorical variable.)

Thanks for any suggestions.

Jacob A. Wegelin
Assistant Professor
Department of Biostatistics
Virginia Commonwealth University
730 East Broad Street Room 3006
P. O. Box 980032
Richmond VA 23298-0032
U.S.A.
E-mail: jwege...@vcu.edu
URL: http://www.people.vcu.edu/~jwegelin

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to