[R] ggplot2: scale_y_log10() with geom_histogram

Joshua Wiley jwiley.psych at gmail.com
Tue Mar 29 21:27:42 CEST 2011


Hi Markus,

In some ways, this is not the most elegant solution ever, as you have
to manually pick some limits, but it is fairly straightforward:

qplot(exp(rnorm(1000))) +
  geom_histogram(colour = "cornsilk", fill ="darkblue") +
  scale_x_sqrt() +
  scale_y_log10() +
  coord_cartesian(ylim = c(10^0, 10^2.5))

Just use the ylim argument to coord_cartesian() to "zoom in" on the
part of the graph you want.  The only trick is picking an upper value.

Cheers,

Josh

P.S. There is a google list devoted explicitly to ggplot2, where a lot
more users hang out and you may get faster/more thorough responses.

On Tue, Mar 29, 2011 at 12:13 PM, Markus Loecher
<markus.loecher at gmail.com> wrote:
> Dear ggplot2 users,
> is there an easy/elegant way to suppress zero count bars in histograms with
> logarithmic y axis ?
> One (made up) example would be
>
> qplot(exp(rnorm(1000))) + geom_histogram(colour = "cornsilk", fill =
> "darkblue") + scale_x_sqrt() + scale_y_log10()
>
>
>
> Thanks!
>
> Markus
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list