[R] Converting numbers to percentages for boxplots

David Winsemius dwinsemius at comcast.net
Tue Nov 16 00:59:20 CET 2010

On Nov 15, 2010, at 5:33 PM, daniel carawan wrote:

> Hi,
> I need to convert general numbers to percentages in R to create a  
> boxplot for purposes of comparison.
> Can you please tell me how I can do that? My data is attached as a  
> csv file.

No, it's not. Please read the Posting Guide. (.csv is not an accepted  
file extension)

Are you sure you want a box-and-whiskers plot? I would think that an  
exression such as a percentage wouldn't make much sense when plotting  
values that depend on a distribution of raw numbers. Maybe you meant  
barplot?  Nonetheless, let's press on...
print, format, or sprintf can create strings from numbers. Generally  
one would multiply a proportion by 100 and stick a "%" sign after it.  
And usually the labels can be in a form:
bwp1 <- boxplot(count~spray, data = InsectSprays, axes=FALSE,col =  
axis(2 , at=InsectSprays$count, labels= sprintf("%.1f%%",  
100*InsectSprays$count/sum(InsectSprays$count)) )
# not sure that made any sense.
axis(1 , at=1:6, labels= bwp1$names )

> Thanks.
> Daniel
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT

More information about the R-help mailing list