[R] Drawing a line in xyplot
David Winsemius
dwinsemius at comcast.net
Sat Apr 7 14:59:18 CEST 2012
On Apr 6, 2012, at 9:41 PM, wcheckle wrote:
> i am trying to replicate the following graph using xyplot :
>
> attach(x)
> plot ( jitter(type), mortality, pch=16, xlim = c(0.25, 3.75))
> lines ( c(1-0.375,1.375) , c ( median(mortality[type==1]),
> median(mortality[type==1])), lwd=5,col=2)
> lines ( c(2-0.375,2.375) , c ( median(mortality[type==2]),
> median(mortality[type==2])), lwd=5,col=2)
> lines ( c(3-0.375,3.375) , c ( median(mortality[type==3]),
> median(mortality[type==3])), lwd=5,col=2)
> detach(x)
>
> in the above graph, i draw a median line for "mortality" (range from
> 5 to
> 35) by "type" (1,2 or 3). i now have an additional variable
> "attend" (0 or
> 1). within each panel (three panel, one for each "type"), i would
> like to
> draw the median "mortality" for each instance of "attend". i have
> been able
> to get as far as plotting everything but the median lines:
>
> x11(height=8,width=11)
> xyplot ( mortality ~ attend|type,
> panel=function(x,y,subscripts){panel.grid(lty=5);
> panel.xyplot(x,y,pch=16,jitter.x=TRUE,col=1)},
> strip=strip.custom(which.given=1, bg="orange"),data
> =x,aspect=2:1,layout=c(3,1))
>
> any suggestions on how to add the median lines of "mortality" for each
> instance of "attend" within each panel of "type"?
Without data, .... I will only offer that there are functions to draw
lines inside lattice panels. (And will not that this information is
also offered on the main ?Lattice page.)
??llines
??panel.abline
--
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list