Dear R-users, I'm using lattice package and function xyplot for the first time so you will excuse me for my inexperience. I'm facing quite a simple problem but I'm having troubles on how to solve it, I've read tons of old mails in the archives and looked at some slides from?Deepayan Sarkar but still can not get the point. This is the context. I've got data on 9 microRNAs, each miRNA has been measured on three different arrays and on each array I have 4 replicates for each miRNA, which sums up to a total of 108 measurements. I've the suspect that measurement on the first array are systematically lower than the others so I wanted to draw some line plot where each panel correspond to a miRNA, and each line correspond to one of the four replicates (that is: first replicate of miRNA A on array 1 must be connected to first replicate of miRNA A on array 2 and so on), so that for each panel there are 4 series of three points connected by a line/segment. I've done this easily with lattice doing this: array = rep(c("A","B","C"),each = 36) # array replicate spot = ?rep(1:4,27) # miRNA replicate on each array miRNA =?rep(rep(paste("miRNA",1:9,sep="."),each=4),3) # miRNA label exprs = rnorm(mean=2.8,n = 108) # intensity data = data.frame(miRNA,array,spot,exprs) xyplot(exprs ~ array|miRNA,data=data,type="b",groups=spot,xlab="Array",ylab = "Intensity",col="black",lty=2:5,scales = list(y = list(relation "free"))) Now, I want to superpose to each panel an other series of three points connected by a line, where each point represent the mean of the four replicates of the miRNA on each array, a sort of mean line. I've tried using the following, but it's not working as expected: xyplot(exprs ~ array|miRNA,data=array,type="b",groups=spot,xlab="Array",ylab = "Intensity",col="black",lty=2:5,scales = list(y = list(relation "free")), panel = function(x,y,groups,subscripts){ panel.xyplot(x,y,groups=groups,subscripts=subscripts) panel.superpose(x,y,panel.groups=panel.average,groups=groups,subscripts=subscripts) }) This is maybe a silly question and possibly there's a trivial way to do it, but I can not figure it out. Thanx for any help. niccol?
Dear R-users, I'm using lattice package and function xyplot for the first time so you will excuse me for my inexperience. I'm facing quite a simple problem but I'm having troubles on how to solve it, I've read tons of old mails in the archives and looked at some slides from?Deepayan Sarkar but still can not get the point. This is the context. I've got data on 9 microRNAs, each miRNA has been measured on three different arrays and on each array I have 4 replicates for each miRNA, which sums up to a total of 108 measurements. I've the suspect that measurement on the first array are systematically lower than the others so I wanted to draw some line plot where each panel correspond to a miRNA, and each line correspond to one of the four replicates (that is: first replicate of miRNA A on array 1 must be connected to first replicate of miRNA A on array 2 and so on), so that for each panel there are 4 series of three points connected by a line/segment. I've done this easily with lattice doing this: array = rep(c("A","B","C"),each = 36) # array replicate spot = ?rep(1:4,27) # miRNA replicate on each array miRNA =?rep(rep(paste("miRNA",1:9,sep="."),each=4),3) # miRNA label exprs = rnorm(mean=2.8,n = 108) # intensity data = data.frame(miRNA,array,spot,exprs) xyplot(exprs ~ array|miRNA,data=data,type="b",groups=spot,xlab="Array",ylab = "Intensity",col="black",lty=2:5,scales = list(y = list(relation "free"))) Now, I want to superpose to each panel an other series of three points connected by a line, where each point represent the mean of the four replicates of the miRNA on each array, a sort of mean line. I've tried using the following, but it's not working as expected: xyplot(exprs ~ array|miRNA,data=array,type="b",groups=spot,xlab="Array",ylab = "Intensity",col="black",lty=2:5,scales = list(y = list(relation "free")), panel = function(x,y,groups,subscripts){ ? ? ? ?panel.xyplot(x,y,groups=groups,subscripts=subscripts) ? ? ? ?panel.superpose(x,y,panel.groups=panel.average,groups=groups,subscripts=subscripts) }) This is maybe a silly question and possibly there's a trivial way to do it, but I can not figure it out. Thanx for any help. niccol?
Hi: Here's one way to do it, adding the latticeExtra package: array = rep(c("A","B","C"),each = 36) # array replicate spot = rep(1:4,27) # miRNA replicate on each array miRNA = rep(rep(paste("miRNA",1:9,sep="."),each=4),3) # miRNA label exprs = rnorm(mean=2.8,n = 108) # intensity dat = data.frame(miRNA,array,spot,exprs) library(latticeExtra) p0 <- xyplot(exprs ~ array|miRNA, data=dat, type="b", groups = spot, xlab="Array", ylab = "Intensity", col="black", lty = 2:5, scales = list(y = list(relation = "free")) ) p1 <- xyplot(exprs ~ array|miRNA, data=dat, type="a", xlab="Array", ylab = "Intensity", col="red", lty = 1, lwd = 2, scales = list(y = list(relation = "free")) ) p0 + p1 You can also write a panel function to do this if you wish. HTH, Dennis 2011/10/10 Niccol? Bassani <biostatistica at gmail.com>:> Dear R-users, > I'm using lattice package and function xyplot for the first time so > you will excuse me for my inexperience. I'm facing quite a simple > problem but I'm having troubles on how to solve it, I've read tons of > old mails in the archives and looked at some slides from?Deepayan > Sarkar but still can not get the point. > > This is the context. I've got data on 9 microRNAs, each miRNA has been > measured on three different arrays and on each array I have 4 > replicates for each miRNA, which sums up to a total of 108 > measurements. I've the suspect that measurement on the first array are > systematically lower than the others so I wanted to draw some line > plot where each panel correspond to a miRNA, and each line correspond > to one of the four replicates (that is: first replicate of miRNA A on > array 1 must be connected to first replicate of miRNA A on array 2 and > so on), so that for each panel there are 4 series of three points > connected by a line/segment. I've done this easily with lattice doing > this: > > array = rep(c("A","B","C"),each = 36) # array replicate > spot = ?rep(1:4,27) # miRNA replicate on each array > miRNA =?rep(rep(paste("miRNA",1:9,sep="."),each=4),3) # miRNA label > exprs = rnorm(mean=2.8,n = 108) # intensity > data = data.frame(miRNA,array,spot,exprs) > xyplot(exprs ~ array|miRNA,data=data,type="b",groups=spot,xlab="Array",ylab > = "Intensity",col="black",lty=2:5,scales = list(y = list(relation > "free"))) > > Now, I want to superpose to each panel an other series of three points > connected by a line, where each point represent the mean of the four > replicates of the miRNA on each array, a sort of mean line. I've tried > using the following, but it's not working as expected: > > xyplot(exprs ~ array|miRNA,data=array,type="b",groups=spot,xlab="Array",ylab > = "Intensity",col="black",lty=2:5,scales = list(y = list(relation > "free")), panel = function(x,y,groups,subscripts){ > ? ? ? ?panel.xyplot(x,y,groups=groups,subscripts=subscripts) > ? ? ? ?panel.superpose(x,y,panel.groups=panel.average,groups=groups,subscripts=subscripts) > }) > > This is maybe a silly question and possibly there's a trivial way to > do it, but I can not figure it out. > > Thanx for any help. > > niccol? > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
2011/10/10 Niccol? Bassani <biostatistica at gmail.com>:> Dear R-users, > I'm using lattice package and function xyplot for the first time so > you will excuse me for my inexperience. I'm facing quite a simple > problem but I'm having troubles on how to solve it, I've read tons of > old mails in the archives and looked at some slides from?Deepayan > Sarkar but still can not get the point. > > This is the context. I've got data on 9 microRNAs, each miRNA has been > measured on three different arrays and on each array I have 4 > replicates for each miRNA, which sums up to a total of 108 > measurements. I've the suspect that measurement on the first array are > systematically lower than the others so I wanted to draw some line > plot where each panel correspond to a miRNA, and each line correspond > to one of the four replicates (that is: first replicate of miRNA A on > array 1 must be connected to first replicate of miRNA A on array 2 and > so on), so that for each panel there are 4 series of three points > connected by a line/segment. I've done this easily with lattice doing > this: > > array = rep(c("A","B","C"),each = 36) # array replicate > spot = ?rep(1:4,27) # miRNA replicate on each array > miRNA =?rep(rep(paste("miRNA",1:9,sep="."),each=4),3) # miRNA label > exprs = rnorm(mean=2.8,n = 108) # intensity > data = data.frame(miRNA,array,spot,exprs) > xyplot(exprs ~ array|miRNA,data=data,type="b",groups=spot,xlab="Array",ylab > = "Intensity",col="black",lty=2:5,scales = list(y = list(relation > "free"))) > > Now, I want to superpose to each panel an other series of three points > connected by a line, where each point represent the mean of the four > replicates of the miRNA on each array, a sort of mean line. I've tried > using the following, but it's not working as expected: > > xyplot(exprs ~ array|miRNA,data=array,type="b",groups=spot,xlab="Array",ylab > = "Intensity",col="black",lty=2:5,scales = list(y = list(relation > "free")), panel = function(x,y,groups,subscripts){ > ? ? ? ?panel.xyplot(x,y,groups=groups,subscripts=subscripts) > ? ? ? ?panel.superpose(x,y,panel.groups=panel.average,groups=groups,subscripts=subscripts) > })Is this close to what you are looking for? xyplot(exprs ~ array | miRNA, data = data, col="black",lty=2:5, type="b", groups=spot, xlab="Array", ylab = "Intensity", scales = list(y = list(relation = "free")), panel = function(x, y, groups, subscripts, ...){ panel.xyplot(x, y, groups=groups, subscripts=subscripts, ...) panel.average(x, y, col = "grey", lwd = 2, horizontal = FALSE) }) -Deepayan