[R] Help with doing overlays plots...

Chuck Cleland ccleland at optonline.net
Mon Aug 8 19:19:27 CEST 2005


trellis.device()

xyplot(states ~ size, groups=type, data=tmp,
                 panel = "panel.superpose",
                 panel.groups ="panel.linejoin", auto.key=TRUE)

Jamieson Cobleigh wrote:
> I have a data frame with three columns, type (a factor with two
> values:  "Monolithic" and "Compositional"), size (numeric), and states
> (numeric).  I want to create a plot where size goes on the x-axis and
> states goes on the y-axis.  In this plot, I want two lines, one where
> the type is "Monolithic" and one where the type is "Compositional".
> 
> I think this can be done by using the plot command to plot the line
> for one of the two types (setting the xlim and ylim parameters to
> ensure the plot area is large enough to hold all of the points). 
> Then, I can use the lines and points commands to add the second line
> onto the plot.
> 
> However, I don't want to have to specify the legend manually.  I want
> something in R that does what can be done in SAS by using "plot
> states*size=type" in "proc gplot".
> 
> Here is a dump of my data set:
> 
> tmp <-
> structure(list(type = structure(as.integer(c(2, 2, 2, 1, 1, 1, 
> 1, 1)), .Label = c("Compositional", "Monolithic"), class = "factor"), 
>     size = as.integer(c(2, 3, 4, 2, 3, 4, 5, 6)), states = as.integer(c(4910, 
>     336026, 37526650, 4016, 44941, 310553, 8260254, 144145585
>     ))), .Names = c("type", "size", "states"), row.names = c("1", 
> "2", "3", "4", "5", "6", "7", "8"), class = "data.frame")
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 452-1424 (M, W, F)
fax: (917) 438-0894




More information about the R-help mailing list