[R] Plotting by Group

Dieter Menne dieter.menne at menne-biomed.de
Thu Oct 14 08:33:10 CEST 2010



Ado wrote:
> 
> 
> My data:
> 
> X        Y            Species             Group
> 0           0            A                        1
> .            .             A                        1
> .            .             A                        1
> I want to plot X vs Y for each species onto the same plot, using lines. 
> In other words, I need 30 different lines each plotted between 0 and  1 on
> the x axis and 0 and 100 on the y, but they need to be grouped by the
> Species, otherwise the lines return from  100 to 0 at the end of the data
> from each species.
> 
> 
Probably not exactly what you want, but some permutations of group and
|Species should work.

Dieter

library(lattice)
n= 200
dat = data.frame(X=sample(1:99,n,TRUE), Y=sample(0:1,n,TRUE),
           
Species=sample(c("A","B"),n,TRUE),Group=as.factor(sample(1:3,n,TRUE)))
# avoid criss-cross by ordering
dat = dat[with(dat,order(X,Y,Species,Group)),] 
xyplot(X~Y|Species, group=Group,data=dat,type="l")


-- 
View this message in context: http://r.789695.n4.nabble.com/Plotting-by-Group-tp2994780p2994867.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list