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

R codeplayer rcodeplayer at gmail.com
Fri Jun 26 06:07:08 CEST 2015


Hi Duncan,


thank you so much for your help.


2015-06-26 4:16 GMT+02:00 Duncan Mackay <dulcalma at bigpond.com>:
> I am not sure that changing the aspect ratio by using
> levelplot(plotMatrix[,,2],
>                  aspect = 1/0.6,
>                  ...)

I already experimented with different values of aspect but I newer get
the height of the groups to match


>
> will do the job as I seem to remember doing something like that when first looking at your problem. There were unwanted side effects
>
> using grid.arrange is the quick way to fill the plot area, I rarely use it
>
> You may be better off by using print - I have not got your original data so I can only guess
> eg
>
> print(plot2, position = c(0.2,0,0.8,0.5), more = TRUE)
> print(plot1 position = c(0,0.5,1.1), more = FALSE)

In this approach, I get a different size for the height and width of the groups.

> You may have to fiddle with the position values for plot2 to get it right.
>
> If the text of plot2 is too small then you could put a line in to get plot2
> par.settings = list(fontsize = list(text = 12.5, points = 8)),
> this is device dependent and you may need to change it
>
>  Regards
>
> Duncan
>

Thank you for your time

> -----Original Message-----
> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of R codeplayer
> Sent: Thursday, 25 June 2015 21:01
> To: r-help at r-project.org
> Subject: Re: [R] R lattice : labeling of matrix groups of different size with strips
>
> 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()
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.



More information about the R-help mailing list