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

R codeplayer rcodeplayer at gmail.com
Thu Jun 25 13:01:24 CEST 2015


Hi Duncan,


thank you very much for your help.


Originally, I thought that it is possible to use a different data
representation and then to automatically create the plots and strips
in lattice.

Based on your suggestion, I could write the code for an annotated
levelplot of the two groups (code is shown below).

An open question is how to display the two groups with the same aspect
ratio for the rows.


> plotMatrix
> , , group1
>
>   a b c d
> 1 1 0 0 0
> 2 1 0 0 0
> 3 1 1 0 0
> 4 0 1 0 0
> 5 0 1 1 0
>
> , , group2
>
>    a  b  c  d
> 1  0  0  1  0
> 2  0  0  1  1
> 3  0  0  0  1
> 4 NA NA NA NA
> 5 NA NA NA NA

library(gridExtra)

trellis.device(device = "pdf",file
="lattice_annotated_groups.pdf",width=8,height=5)

#The aspect="fill" option was added to coerce the same height of the 2 plots
#panel.text was used instead of grid.text to avoid using the
latticeExtra package

plot1 <- levelplot(plotMatrix[,,1],
             page = function(n)
             panel.text("group 1",
                 x = 0.5,
                 y = 0.96),
             colorkey = F,
             xlab = "",
             ylab="",
             aspect="fill")

pm <- plotMatrix[1:3,,2]
colnames(pm) <- rep("",ncol(pm))

plot2 <-levelplot(pm,
            page = function(n)
            panel.text(
                "group 2",
                 x = 0.5,
                 y = 0.96),
            colorkey = F,
            xlab = "",
            ylab="",
            aspect="fill")


grid.arrange(plot1,plot2,ncol=2)
dev.off()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lattice_annotated_groups.pdf
Type: application/pdf
Size: 4703 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20150625/0827d74f/attachment.pdf>


More information about the R-help mailing list