[R] Superposing mean line to xyplot

Niccolò Bassani biostatistica at gmail.com
Mon Oct 10 18:33:40 CEST 2011


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ò



More information about the R-help mailing list