[R] Adding mean values to boxplots
tom.albery at tribalgroup.com
Thu Mar 15 13:04:28 CET 2012
I was wondering if anyone might be able to help me as I'm pretty new to R.
I'm trying to create a boxplot from a data table returned from an sproc. I
have the following code, which generates the plot as I'd like it:
conn <- odbcConnect("datawarehouse"); # connect to datawarehouse
results <- sqlQuery(conn, "call sproc)");
ylab <- 'Percentage (%)'
main = 'Productivity Overview - 6 mnths';
par(mai=c(1.5,1,1,0.2), las = 2, xpd=TRUE, cex.axis=0.8, cex.lab=0.8);
col = c('forestgreen', 'forestgreen', 'forestgreen', 'chocolate',
'chocolate', 'chocolate', 'goldenrod', 'goldenrod', 'goldenrod');
b <- results[,4:12]
boxplot(b, col=col, ylab=ylab, main=main, boxwex=0.4);
What i'd like to do is add the mean value, demarcated by the black line in
the middle of each box, to the plot. The only way I've managed to add values
previously is by specifying their exact value and location on the plot e.g.
text(1.4,2.139,format("Mean (2.14)",digits=2), cex=1);
I need these values to be dynamic in the sense that they will be different
each time the graph is generated (based on the parameters passed through the
sproc) and will need to be in a different position each time (i.e. in-line
with the mean for each box).
I'm uncertain about a. whether this is possible in R and b. if it is
possible, how best I could achieve it.
If anyone has any advice it would be gratefully received.
Thanks in advance.
View this message in context: http://r.789695.n4.nabble.com/Adding-mean-values-to-boxplots-tp4474700p4474700.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help