[R] Boxplot with Log10 and base-exponent axis
Luigi
marongiu.luigi at gmail.com
Sat Jun 23 17:48:42 CEST 2012
Thank you!
This works good. I understand that the value are now in Log10 scale,
although I did not understand what is happening at line 4 of your script.
I would like to ask how can I change the y limits since they now depend on
par("user"). What if I'd like y limits extending from 1000 to 1 000 000?
I've tried to modify ylim (line 3) and ceiling (line 4) but I obtained
errors.
Best wishes,
Luigi
############### UPDATED EXAMPLE ############################################
# generationg random numbers
x<-runif(100, min=0, max=100000)
#plotting
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)))))
############################################################################
#
------------------ Your Response
--------------------------------------------
The key is to supply an expression, not text, to the labels argument to
axis.
See help("plotmath") for details. Here is an example:
1 x <- list(One=10^(sin(1:10)+5), Two=10^(cos(1:30)*2))
2 boxplot(x, log="y", yaxt="n")
3 ylim <- par("usr")[3:4]
4 log10AtY <- seq(ceiling(ylim[1]), floor(ylim[2]))
5 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