[R] Histograms on a log scale

John Kane jrkrideau at yahoo.ca
Mon Jul 20 15:44:41 CEST 2009


How about using the ggplot2 package? Does this give you something along the lines of what you want?  
=======================================================================
library(ggplot2)
r <- data.frame(rlnorm(1000))
names(r) <- "rr"

ggplot(r, aes(rr)) + geom_histogram()+ scale_x_log10() + scale_y_log10()

=========================================================================

--- On Mon, 7/20/09, Lorenzo Isella <lorenzo.isella at gmail.com> wrote:

> From: Lorenzo Isella <lorenzo.isella at gmail.com>
> Subject: [R] Histograms on a log scale
> To: r-help at r-project.org
> Received: Monday, July 20, 2009, 5:17 AM
> Dear All,
> I would like to be able to plot histograms/densities on a
> semi-log or log-log scale.
> I found several suggestions online
> 
> http://tolstoy.newcastle.edu.au/R/help/05/09/12044.html
> https://stat.ethz.ch/pipermail/r-help/2002-June/022295.html
> http://www.harding.edu/fmccown/R/#histograms
> 
> Now, consider the code snippet taken from http://www.harding.edu/fmccown/R/#histograms
> 
> # Get a random log-normal distribution
> r <- rlnorm(1000)
> 
> # Get the distribution without plotting it using tighter
> breaks
> h <- hist(r, plot=F, breaks=c(seq(0,max(r)+1, .1)))
> 
> # Plot the distribution using log scale on both axes, and
> use
> # blue points
> plot(h$counts, log="xy", pch=20, col="blue",
>    main="Log-normal distribution",
>    xlab="Value", ylab="Frequency")
> 
> This is very close to what I need, but how can I have
> filled rectangles in the plot, so that it looks more like a
> traditional histogram?
> Kind Regards
> 
> Lorenzo
> 
> ______________________________________________
> 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.
> 


      __________________________________________________________________
The new Internet Explorer® 8 - Faster, safer, easier.  Optimized for Yahoo!  



More information about the R-help mailing list