[R] multiple qplot histograms in one plot

Erik Iverson eriki at ccbr.umn.edu
Fri May 21 20:12:54 CEST 2010



rajesh j wrote:
> Hi,
> 
> I wish to plot multiple histograms(representing different data so different
> range along xaxis but y axis is the same) horizontally in ggplot2. I'd like
> it to look like facets. Is this possible?

Can you give a small example, say, using the diamonds dataset, or one of 
your own?  What's wrong with:

   data(diamonds)
   qplot(carat, data = diamonds,
         facets = color ~ .,
         geom = "histogram",
         binwidth = 0.1, xlim = c(0,3))

which is Figure 2.16 in the ggplot2 book.  You can change this to be 
horizontal.

Unless you mean different variables completely, in which case you can 
create your own grid viewports, or possibly use the reshape package 
along with faceting.  Without a concrette example, it's hard to offer 
more help.



More information about the R-help mailing list