I'm trying to generate a few related plots, each with one stat_summary
layer. The issue I have is that the range for the y-axis is set to
include all the data if I were to add e.g. a geom_point() or a
geom_boxplot() layer on the plot. I was wondering if the final y
limits could automatically adjust to the final stat layer that is
included rather than the original data that was used to generate the
stat.
Here's a small example. The effect isn't as pronounced here as it is on my data.
x<-runif(100,1,80)
y<-runif(100,15,110)
z<-runif(100,35,180)
dfr<-melt(data.frame(x,y,z))
pp<-ggplot(dfr)+aes(x=variable,y=value)
pp1<-pp+geom_point()
pp2<-pp+stat_summary(fun.data="mean_cl_boot")
The limits for pp2 are the same as for pp1. I would have expected pp2
to have limits of maybe 35 to 115 or so.
Here's a link to an example plot from my data:
http://dl.dropbox.com/u/614041/web/testylimit.pdf . Before I
discovered stat_summary I used to do this manually (!) and with those
plots the y limit was from around 2 to 7. I know I could fix this
manually by adding coord_cartesian(ylim=c(2,7)) to the plot but I
would prefer not to have to for all the different plots that need to
be generated from this data set.
What am I missing?
Faisal Moledina
This is a limitation of the way that scales work in ggplot2. The
basic problem is this: some statistics (bin, density, function,
smooth) need to know the range of the data so that they can perform
their jobs properly. That means that position scales need to be
trained prior to the computation of statistics - so their range will
always include the range of the original data. One way to work around
this would be to reset the position scales after the statistics have
been computed - so instead of just expanding the limits if they were
bigger, statistics could also effectively shrink the limits if they
were smaller.
I think this behaviour is a bug, but I'd appreciate comments if you've
found this behaviour annoying or helpful.
Hadley
> --
> 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
>
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
I think that resetting the position scales after the statistics have
been computed is along the lines of what I'm looking for. Shrinking
the limits if they are smaller would be perfect. It's a minor
annoyance right now and if it would be a quick enough fix to be able
to shrink the limits, it would be very helpful.
Faisal
Hadley