[R] Median line with stripchart

S Ellison S.Ellison at LGCGroup.com
Thu Jun 14 16:41:24 CEST 2012


 

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Luigi
> Sent: 14 June 2012 00:44
> To: dcarlson at tamu.edu
> Cc: r-help at r-project.org
> Subject: Re: [R] Median line with stripchart
> 
> Sorry for the inconvenience,
> I have added an EXAMPLE. Here I am plotting few data with the 
> relative median values. The median are added ad hoc using the 
> points() function, which is not really professional and is 
> time consuming. With boxplot() the median values are 
> automatically drawn, with striplot() this is not true and I 
> couldn't find another suitable package.

Two things:
- you could use segments() to drw the lines
- you don't have to plot each point individually

Example
y <- rnorm(3*17, 11) #some data
g <- gl(3, 17) #Generate a grouping factor

stripchart(y~g, ylim=c(0.5,3.5)) #leave some space
	#defaults to unit locations for groups

meds <- tapply(y,g,median) #get the medians in factor level order - same order as stripchart
loc.strip <- 1:3
segments(meds,  loc.strip-0.3, meds, loc.strip+0.3, col=2, lwd=3)
	#adjust the line length with the 0.3 and the thickness with lwd as usual
*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}



More information about the R-help mailing list