[R] boxplot - labelling

Joerg van den Hoff j.van_den_hoff at fz-rossendorf.de
Mon May 8 13:19:36 CEST 2006


Sachin J wrote:
> Hi,
>    
>   How can I get the values of mean and median (not only points but values too) on the boxplot. I am using boxplot function from graphics package. Following is my data set
>    
>   > df 
>   [1]  5  1  1  0  0 10 38 47  2  5  0 28  5  8 81 21 12  9  1 12  2  4 22  3
>    
>   > mean.val <- sapply(df,mean)
>> boxplot(df,las = 1,col = "light blue")
>> points(seq(df), mean.val, pch = 19)
>    
>   I could get mean as dot symbol but i need values too? Also how to print the x-axis labels vertically instead of horizontally? Is there any other function to achieve these?
>    
>   Thanx in advance.
>    
>   Sachin
> 
>    
>    
> 
> __________________________________________________
> 
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

use

par(las = 3)
bxp <- boxplot(df,las = 1,col = "light blue")

to control label orientation and access the data displayed in the 
boxplot (see `?par', `?boxplot')

use

text(x, y, 'some_text_or_number')

to add text to the boxplot. for x, use the 'number of the box' (i.e. `1' 
in the example above). for y use the mean or median or whatever you wanted).


joerg




More information about the R-help mailing list