[R] Boxplot with Log10 and base-exponent axis

William Dunlap wdunlap at tibco.com
Fri Jun 22 17:14:11 CEST 2012


The key is to supply an expression, not text, to the labels argument to axis.
See help("plotmath") for details.  Here is an example:
  x <- list(One=10^(sin(1:10)+5), Two=10^(cos(1:30)*2))
  boxplot(x, log="y", yaxt="n")
  ylim <- par("usr")[3:4]
  log10AtY <- seq(ceiling(ylim[1]), floor(ylim[2]))
  axis(side=2, at=10^log10AtY, lab=as.expression(lapply(log10AtY, function(y)bquote(10^.(y)))))

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of Luigi
> Sent: Friday, June 22, 2012 7:54 AM
> To: r-help at r-project.org
> Subject: [R] Boxplot with Log10 and base-exponent axis
> 
> Dear all,
> 
> I would like to (i) produce boxplot graphs with axis in logarithm in base 10
> and (ii) showing the values on the axis in 10^exponent format rather than
> 10E+exponent.
> 
> 
> 
> To illustrate with an example, I have some widely spread data that I chart
> plot using  boxplot() [figure on the left]; the log="y" option of boxplot()
> I obtained the natural logarithm conversion of the data and the unfriendly
> notation baseE+exponent [figure on the centre]; if I log10 the data I obtain
> the desired plot, but the axis are showing only the exponent. [figure on the
> right].
> 
> 
> 
> Can anybody help?
> 
> 
> 
> Best regards
> 
> Luigi Marongiu, MSc
> 
> 
> 
> ########### EXAMPLE ############
> 
> # generationg random numbers
> 
> x<-runif(100, min=0, max=100000)
> 
> 
> 
> # create plot
> 
> par(mfrow = c(1,3))
> 
> 
> 
> #plotting in the left side
> 
> boxplot(x, xlab="Linear values")
> 
> 
> 
> #plotting in the centre
> 
> boxplot(x, log = "y", xlab="y axis logged")
> 
> 
> 
> # creating log10 values and plotting on the right side
> 
> Log.base10.x<-log10(x)
> 
> boxplot(Log.base10.x, xlab="LOG10 of data")
> 
> 
> 
> 
> 
> 
> 	[[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.



More information about the R-help mailing list