All, I have been trying to get calls to hist(...) to be plotted with the y-axis having a log scale. I have tried: par(ylog=TRUE) I have also looked at the histogram package. Suggestions welcome. -- Derek M. Jones tel: +44 (0) 1252 520 667 Knowledge Software Ltd mailto:derek at knosof.co.uk Source code analysis http://www.knosof.co.uk
How about computing the log of you variable and calling hist() on the log data. logy <- log(y) Hhist(logy) John John Sorkin Chief Biostatistics and Informatics Univ. of Maryland School of Medicine Division of Gerontology and Geriatric Medicine JSorkin at grecc.umaryland.edu -----Original Message----- From: Derek M Jones <derek at knosof.co.uk> To: <r-help at r-project.org> Sent: 8/29/2010 9:58:35 PM Subject: [R] log y 'axis' of histogram All, I have been trying to get calls to hist(...) to be plotted with the y-axis having a log scale. I have tried: par(ylog=TRUE) I have also looked at the histogram package. Suggestions welcome. -- Derek M. Jones tel: +44 (0) 1252 520 667 Knowledge Software Ltd mailto:derek at knosof.co.uk Source code analysis http://www.knosof.co.uk ______________________________________________ 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. Confidentiality Statement: This email message, including any attachments, is for th...{{dropped:6}}
Hi Derek, Here is an option using the package ggplot2: library(ggplot2) x <- sample(x = 10:50, size = 50, replace = TRUE) qplot(x = x, geom = "histogram") + scale_y_log() However, the log scale is often inappropriate for histograms, because the y-axis represents counts, which could potentially be 0, and therefore undefined (R outputs -Inf). Another option using base graphics would be something along the lines (no pun intended) of: temp <- hist(x, plot = FALSE) #get histogram data plot(x = temp$mids, y = log(temp$counts), type = "h") HTH, Josh On Sun, Aug 29, 2010 at 6:58 PM, Derek M Jones <derek at knosof.co.uk> wrote:> All, > > I have been trying to get calls to hist(...) to be plotted > with the y-axis having a log scale. > > I have tried: par(ylog=TRUE) > > I have also looked at the histogram package. > > Suggestions welcome. > > -- > Derek M. Jones ? ? ? ? ? ? ? ? ? ? ? ? tel: +44 (0) 1252 520 667 > Knowledge Software Ltd ? ? ? ? ? ? ? ? mailto:derek at knosof.co.uk > Source code analysis ? ? ? ? ? ? ? ? ? http://www.knosof.co.uk > > ______________________________________________ > 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/
On 30/08/2010 1:58 p.m., Derek M Jones wrote:> All, > > I have been trying to get calls to hist(...) to be plotted > with the y-axis having a log scale. > > I have tried: par(ylog=TRUE) > > I have also looked at the histogram package. > > Suggestions welcome. >You appear to be looking for a log-histogram function. There is one (logHist) in my package DistributionUtils on CRAN. You don't need the rest of the package to use it. You could just extract that particular function. David Scott -- _________________________________________________________________ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142, NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.scott at auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics