From: Chris Friedl <cfriedalek_at_gmail.com>

Date: Tue, 04 Mar 2008 04:16:42 -0800 (PST)

Date: Tue, 04 Mar 2008 04:16:42 -0800 (PST)

Hi R-help

I'm trying to create a grid plot in which each plot in the grid contains two density plots (colored by factor) and two vertical lines at the respective medians (also colored by the factor).

Using the diamonds dataset as an example, the following commands give me price density plots by factor cut in a single, ungridded plot.

p <- ggplot(data=diamonds, aes(x=price)) + geom_density(aes(color=cut)) p

I can add vertical lines at the medians of each density as follows.

medians <- data.frame(cut=levels(diamonds$cut), intercept=tapply(diamonds$price, list(diamonds$cut), median)) p + geom_vline(data=medians, aes(color=factor(cut)))

I can create a gridded plot of price density by factors cut and color (where color is the grid reference) as follows.

p + facet_grid(color~.)

However I've had no luck trying to now add vertical grid lines on each density plot within each grid. Can anyone offer a suggestion on how to do this?

Is this a limitation with ggplot2? I'm using ggplot2 0.5.7, R 2.6.2, Windows XP.

-- View this message in context: http://www.nabble.com/ggplot2---Problem-with-grid-plot-tp15825952p15825952.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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 04 Mar 2008 - 12:21:21 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 04 Mar 2008 - 13:30:20 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.
*