Histograms next to one another with same x and y scale

63 views
Skip to first unread message

KDB

unread,
Mar 14, 2011, 1:11:18 PM3/14/11
to ggplot2
Hi everybody,

I am creating several histograms for several size classes. Is there an
easy way to plot histograms next to one another with ggplot2 on the
same graph with the same continuous x and y scale. It should look
something like the lower part of this graph without the quantile
regression fitting:
http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=109

Cheers,

Kenneth

Ista Zahn

unread,
Mar 14, 2011, 1:25:27 PM3/14/11
to KDB, ggplot2
Hi Kenneth,
Probably the easiest way is to facet on time. If needed I'll be happy
to give a more detailed explanation if you provide a reproducible
example.

Best,
Ista

> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>

--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

Ravina, Mark

unread,
Mar 14, 2011, 4:07:09 PM3/14/11
to ggplot2
Is there a way to control the whiskers on a boxplot in ggplot (or in R)? I'd like to set them to 95th percentile rather than 1.5 IQR. There is supposedly such a command in the rgr package, but I don't see any change for different values of "wend"?

Thanks,
Mark

Professor of History
Department of History
Emory University
Atlanta, GA 30322
404.727.4025
his...@emory.edu

________________________________

This e-mail message (including any attachments) is for the sole use of
the intended recipient(s) and may contain confidential and privileged
information. If the reader of this message is not the intended
recipient, you are hereby notified that any dissemination, distribution
or copying of this message (including any attachments) is strictly
prohibited.

If you have received this message in error, please contact
the sender by reply e-mail message and destroy all copies of the
original message (including attachments).

KDB

unread,
Mar 15, 2011, 4:51:04 AM3/15/11
to ggplot2
Hi Ista,

My data would look something like this
sizeclass = c(rep(1,times = 15),rep(3, times = 25), rep(7, times =
20))
parameter = c(rnorm(15, mean = 5), rnorm(25, mean = 15),rnorm(20, mean
= 35))
sizeclass <- data.frame(sizeclass,parameter)
I would like to have histograms of the parameter (rotated as in the
example in the link i gave before) ordered along the x-axis according
to their size classes. The histograms should have a common y-axis and
the spacing of the histograms should be in proportion to the
proportions between their respective sizeclasses. I hope this is
understandable. Can this be done with ggplot2 ???

Cheers,

Kenneth



size classes on the x.axis at their proper distance and histog

Brandon Hurr

unread,
Mar 15, 2011, 4:59:15 AM3/15/11
to KDB, ggplot2
This is what I have so far...

ggplot(data=sizeclass, aes(x=parameter))+geom_histogram()+facet_grid(.~sizeclass)+coord_flip()

I don't think the facets can be graphed across like in your example so I'm not sure you can go any further. 

Brandon

Brandon Hurr

unread,
Mar 15, 2011, 5:02:50 AM3/15/11
to KDB, ggplot2
I missed the part about the spacing... when you facet it treats it as a factor. You could chuck in empty data for 2,3,4,and 6 and it should space them appropriately. Otherwise, I'm at a loss. 

If it can be done, I would guess that Takahashi (who is probably very busy/distracted at the moment and hopefully safe), Baptiste, or Hadley might know. 

B

KDB

unread,
Mar 15, 2011, 2:42:24 PM3/15/11
to ggplot2
Ok, thanks for all the suggestions guys...
So, i guess there is really no way to do this, i just figured if
something like this can be done for boxplots, it should also be
possible for histograms...


On Mar 15, 10:02 am, Brandon Hurr <brandon.h...@gmail.com> wrote:
> I missed the part about the spacing... when you facet it treats it as a
> factor. You could chuck in empty data for 2,3,4,and 6 and it should space
> them appropriately. Otherwise, I'm at a loss.
>
> If it can be done, I would guess that Takahashi (who is probably very
> busy/distracted at the moment and hopefully safe), Baptiste, or Hadley might
> know.
>
> B
>
> On Tue, Mar 15, 2011 at 08:59, Brandon Hurr <brandon.h...@gmail.com> wrote:
> > This is what I have so far...
>
> > ggplot(data=sizeclass,
> > aes(x=parameter))+geom_histogram()+facet_grid(.~sizeclass)+coord_flip()
>
> > I don't think the facets can be graphed across like in your example so I'm
> > not sure you can go any further.
>
> > Brandon
>

Hadley Wickham

unread,
Mar 15, 2011, 3:53:41 PM3/15/11
to KDB, ggplot2
It's possible, but you have to do all the calculate by hand. The main
complication is that the y-axis isn't mapped to one variable - but is
a linear combination of time and count. I think this sort of plot
very often makes sense, but it's not entirely clear to me how it
should fit into the grammar.

Hadley

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Hadley Wickham

unread,
Mar 19, 2011, 12:48:10 AM3/19/11
to Ravina, Mark, ggplot2
Hi Mark,

This parameter is currently fixed in ggplot2 - mainly because I think
it easily confuses readers who probably expect a standard boxplot.

Hadley

Reply all
Reply to author
Forward
0 new messages