[R] Problems with Boxplot

Petr PIKAL petr.pikal at precheza.cz
Mon Sep 7 15:02:06 CEST 2009


Hi

r-help-bounces at r-project.org napsal dne 05.09.2009 04:59:41:

> 
> Hi Petr,
> 
> Thanks for these comments.
> 
> I'm sorry that my post was not clear.  I was referring to the questions 
in
> my original post/code/file uploads, but I had forgotten to include an
> updated file (now attached 
> http://www.nabble.com/file/p25304663/Post%2Btrial%2Bdata.csv
> Post+trial+data.csv ) to work with the new code:
> 
> testdata<- c("C:\\Files\\R\\Sample R code\\Post trial data.csv")
> new_data<- read.table(testdata, skip = 0, sep = ",", na.strings =
> "na",header = TRUE)
> x11(width=16, height=7, pointsize=14)
> boxplot(new_data,outline = FALSE, col = c("lightblue", "salmon"), las 
=1,
> boxwex = 0.5) 
> legend("top", c("Label for blue boxes","Label for red boxes"), cex=1.5,
> lty=1:2, fill=c("lightblue", "salmon"), bty="n");
> title(main="Chart title text", cex.main = 1.8)
> grid() 
> 
> I'm still not clear how I can get the number format showing #,###.  E.g.
> with this code and attached file, the scale shows as "2000", "10000" 
etc.  I
> don't know how to show 2,000..... 10,000 etc.  I have looked through 
sprintf
> (thanks for suggesting that - I'd spent hours looking without finding 
it)
> and it seems incredibly flexible, but the formats shown are more 
scientific
> in focus.  I still haven't been able to find a way of getting a "comma
> style".

AFAIK you can not format these in boxplot directly. You need to plot 
without y axis and in axis you can use formating with prettyNum. I found 
quite easily from sprintf and formatC help pages (I did not do it before 
so I learned it now:-)

x<-rnorm(100)+10000
bbb<-boxplot(x, axes=F)
axis(2, at= pretty(x), labels=prettyNum(pretty(x), big.mark=","))

Regards
Petr

> 
> Thanks again
> 
> Guy
> 
> 
> Petr Pikal wrote:
> > 
> > Hi
> > 
> > it is rather difficult to understand what you mean by your 
> > questions/answers without real reproducible code.
> > 
> > r-help-bounces at r-project.org napsal dne 03.09.2009 13:41:11:
> > 
> >>.... I'd be interested if anyone has a quick way to get percentages 
and 
> > additionally, how do I get numbers in the "0,000" format along the x 
or
> > y-axis?  In the meantime, I can live with this.
> > 
> > plot(1:10,1:10, axes=F)
> > axis(2, at=c(2,3,7,9), labels=c(1.2, 2.38, 13.54, 16.8))
> > 
> > the same applies with boxplot.
> > 
> > by
> > 
> > bbb<- boxplot(....)
> > 
> > you obtain an object which is used by bxp. See help page for boxplot, 
> > section See also
> > 
> >> .......
> > 
> > See also par for graphic options, format and or sprintf for formating 
> > numbers 
> > 
> > Regards
> > Petr
> > 
> > 
> 
> -- 
> View this message in context: 
http://www.nabble.com/Problems-with-Boxplot-
> tp25256461p25304663.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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