Dear List, I have the following function where I plot on one page a histogram and a boxplot. I use option labels = TRUE in hist to show labels. However the label on the highest bar in the histogram is not showing entirely. How can I correct this? Thanks for any suggestions? histtst <- function(n = 100,...){ set.seed(15) # makes rnorm reproducible par(mfrow = c(2,1)) x <- rnorm(n) hist(x, labels = TRUE) boxplot(x, horizontal = TRUE) } A. [[alternative HTML version deleted]]
On Fri, 13 Apr 2007, AA wrote:> Dear List, > > I have the following function where I plot on one page a histogram and a > boxplot. I use option labels = TRUE in hist to show labels. However the > label on the highest bar in the histogram is not showing entirely. How > can I correct this?par(xpd=TRUE) will stop the labels being clipped, but I think you need to set ylim in the call to hist to make room for the labels.> Thanks for any suggestions? > > histtst <- > function(n = 100,...){ > set.seed(15) # makes rnorm reproducible > par(mfrow = c(2,1)) > x <- rnorm(n) > hist(x, labels = TRUE) > boxplot(x, horizontal = TRUE) > } > > A. > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
--- AA <aa2007r at gmail.com> wrote:> Dear List, > > I have the following function where I plot on one > page a histogram and a boxplot. > I use option labels = TRUE in hist to show labels. > However the label on the highest bar in the > histogram is not showing entirely. How can I correct > this? > Thanks for any suggestions? > > histtst <- > function(n = 100,...){ > set.seed(15) # makes rnorm reproducible > par(mfrow = c(2,1)) > x <- rnorm(n) > hist(x, labels = TRUE) > boxplot(x, horizontal = TRUE) > }You're running out of room on the y-axis. I don't know how to cure it in general because I don't know how to find the general height of the largest bin but this shows the problem. You need to extend the ylim. histtst <- function(n = 100,...){ set.seed(15) # makes rnorm reproducible par(mfrow = c(2,1)) x <- rnorm(n) hist(x, labels = TRUE, ylim=c(0,8)) boxplot(x, horizontal = TRUE) } hh1 <- histtst(12)
Thanks Prof. Ripley and John for this quick answer. both par(xpd = TRUE) and setting ylim worked. Thanks again. A. ----- Original Message ----- From: "Prof Brian Ripley" <ripley at stats.ox.ac.uk> To: "AA" <aa2007r at gmail.com> Cc: "R-Help" <r-help at stat.math.ethz.ch> Sent: Friday, April 13, 2007 4:09 PM Subject: Re: [R] labels cut partially on hist> On Fri, 13 Apr 2007, AA wrote: > >> Dear List, >> >> I have the following function where I plot on one page a histogram and a >> boxplot. I use option labels = TRUE in hist to show labels. However the >> label on the highest bar in the histogram is not showing entirely. How >> can I correct this? > > par(xpd=TRUE) will stop the labels being clipped, but I think you need to > set ylim in the call to hist to make room for the labels. > >> Thanks for any suggestions? >> >> histtst <- >> function(n = 100,...){ >> set.seed(15) # makes rnorm reproducible >> par(mfrow = c(2,1)) >> x <- rnorm(n) >> hist(x, labels = TRUE) >> boxplot(x, horizontal = TRUE) >> } >> >> A. >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at stat.math.ethz.ch 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. >> > > -- > Brian D. Ripley, ripley at stats.ox.ac.uk > Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ > University of Oxford, Tel: +44 1865 272861 (self) > 1 South Parks Road, +44 1865 272866 (PA) > Oxford OX1 3TG, UK Fax: +44 1865 272595