Re: [R] help with bwplot

From: hadley wickham <h.wickham_at_gmail.com>
Date: Tue, 12 Feb 2008 14:18:50 -0600

> I have following data set, which I want to plot the "Scale" variable on the
> x-axis and "Mean"Žon the y-axis for each Ageclass and for each sex. The Mean
> value of each Ageclass for each sex would be connected by a line. Totally,
> there should be 6 lines, from which three present the Mean values of each
> Ageclass for respective sex. Are there any easy ways to do this in R?

Maybe something like:

install.packages("ggplot2")
library(ggplot2)

qplot(Scale, Mean, data=df, colour=Sex, linetype = Ageclass, geom="line", group=interaction(Sex, Ageclass))

The only possibly non-intuitive thing is the group variable - this specifies the that you want a single line for each combination of sex and ageclass. The default is to draw a line for each combination of all of the categorical variables, which doesn't work here because the x axis is categorical. You might also want to do:

df <- transform(df, Scale = reorder(Scale, Mean))

which orders scale in ascending order of mean Mean.

You can find out more about ggplot2 at http://had.co.nz/ggplot2

Hadley

-- 
http://had.co.nz/

______________________________________________
R-help_at_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.
Received on Tue 12 Feb 2008 - 20:44:34 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 12 Feb 2008 - 21:30:13 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive