subsets

5 views
Skip to first unread message

squid

unread,
Mar 31, 2009, 3:30:24 PM3/31/09
to ggplot2
Hi,
Simple question, so sorry upfront.
How do I define a subset of data?
If I have a particular variable, say "chrom" and 10 different
categories within that variable, how do I plot one of these at a
time?
Facets has been great for plotting them all at the same time using

qplot(position,X, facets= .~chrom, colour=class, size=1)

But now I'd like to plot one chrom at a time. I gather I should use
subset to do this rather than facets? But not really clear on how to
use subset within this format. The following did not plot just the
subset I wanted, but rather all the data.

qplot(position, X, data=subset(alldata, chrom="2L"), colour=class,
size=1).

Many thanks.




hadley wickham

unread,
Mar 31, 2009, 8:24:44 PM3/31/09
to squid, ggplot2
Hi Squid,

You'd want subset(alldata, chrom == "2L")

- notice the double equals!

You might also want to have a look at http://had.co.nz/plyr. There's
an example there showing how to create a plot for each subset of a
bigger dataset.

Hadley
--
http://had.co.nz/
Reply all
Reply to author
Forward
0 new messages