[R] R lattice : labeling of matrix groups of different size with strips

R codeplayer rcodeplayer at gmail.com
Wed Jun 24 15:10:02 CEST 2015


In R lattice, I am trying to label predefined groups of rows in a
matrix of data with strips. Currently, the length of the strips fail
to match the different sizes of the groups as the data representation
only allows groups with the same size.

One possibility to solve this might be to suppress the display of
NAs, but I did not find any configuration to realize
this in Lattice.

The example code below shows a matrix (m) with 8 rows and 4 columns.
Group 1 contains row 1-5 and group 2 contains row 6-8. The lattice
output is attached below the code.

Thank you for your time



library(lattice)

m <- matrix(c(1,1,1,0,0,0,0,0,
            0,0,1,1,1,0,0,0,
            0,0,0,0,1,1,1,0,
            0,0,0,0,0,0,1,1),nrow=8,ncol=4)

group1 <- m[1:5,]
group2 <- m[6:nrow(m),]

plotMatrix <- array(dim=c(5,4,2))
dimnames(plotMatrix) <- list(rep("",5), c("a","b","c","d"),c("group1","group2"))
plotMatrix[,,1]<- group1
plotMatrix[1:3,,2] <- group2

trellis.device(device = "pdf",file ="lattice_strips.pdf",width=14,height=10)
print(levelplot(plotMatrix,colorkey=F,xlab="",ylab=""))
dev.off()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lattice_strips.pdf
Type: application/pdf
Size: 4678 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20150624/e6b7d4ac/attachment.pdf>


More information about the R-help mailing list