Sub-grouping in a plot in R -


i want represent data different individual cells in xyplot , give them color in base of different category. however, when have been able represent dots:

xyplot( signal ~ time | as.factor(treatment), data=data,groups=cell,         fill.color = as.character(data$color),         panel = function(x, y,fill.color,...,subscripts){           fill = fill.color [subscripts]           panel.xyplot(x, y,pch=19, col=fill, type ="p")} ) 

but in way imposible visually track cells. therefore, want same lines , polygons error area happens each time try, lattice override second group should assign color (or not able tell lattice. here way that:

cell<-rep(x = c("a","b","c","d"),50) signal<-rep(sample(seq(from = 0, = 50, = 1), size = 50, replace = true),4) time<-sort(rep(seq(1,50),4),decreasing = f) treatment<-rep(c("hard","soft"),50*2) color<-rep(c("red","orange"),50*2) data<-data.frame(cell,signal,time,treatment,color)  my.panel2 <- function(x, y, subscripts, col, pch,cex,sd,fill.color,...) {   low95 <- y-sd[subscripts]   up95 <- y+sd[subscripts]   fill=fill.color [subscripts]   panel.xyplot(x, y, col=fill.color, pch=pch,cex=cex, ...)   panel.arrows(x, low95, x, up95, angle=90, code=3,lwd=3,                 length=0.05, alpha=0.2,col=col) }   xyplot(signal~time|as.factor(treatment), groups=as.factor((data$cell)),         data=data, type='l',        color.line=as.character((data$color))) 

thanks; santi

thanks @vince, gave me interesting idea. ggplot2 based on layers decided try similar in lattice as.layer(). first spitted data in 3 groups, 1 per level

fm1<-filter(fmeans, group=="ave-int") fm2<-filter(fmeans, group=="mini-int") fm3<-filter(fmeans, group=="high-int") line1<-fm2[43,] fm3<-rbind(fm3,line1) 

then decided use polygon error band using panel.polygon():

my.panel.pol <- function(x, y, subscripts, col,sd,...) {   plot.line <- trellis.par.get("plot.line")   xs <- if(is.factor(x)) {     factor(c(levels(x) , rev(levels(x))), levels=levels(x))   } else {     xx <- sort(unique(x))     c(xx, rev(xx))   }   low95 <- y-sd[subscripts]   up95 <- y+sd[subscripts]   panel.xyplot(x, y, col=col,...)   panel.polygon(xs, c(up95, rev(low95)), col=col, alpha=0.2, border=f) } 

then represent data , merge in 1 graphic

   a<-       xyplot(mean ~ slice*12 |treatment , fm1,               layout=c(2,2),col="red",              grid=t,              ylim = c(0,max(fmeans$mean)),               group = stemcell, type = "l",              sd=fm1$sd,              panel.groups= "my.panel.pol",              panel="panel.superpose")     b<-xyplot(mean ~ slice*12 |treatment , fm2,               layout=c(2,2),col="blue",               group = stemcell, type = "l",               sd=fm2$sd,               panel.groups= "my.panel.pol",               panel="panel.superpose")     c<-xyplot(mean ~ slice*12 |treatment , fm3,               layout=c(2,2),col="green",               group = stemcell, type = "l",               sd=fm3$sd,               panel.groups= "my.panel.pol",               panel="panel.superpose")      a+as.layer(b)+as.layer(c) 

so here result:

enter image description here


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -