[R] dendrogramGrob cuts off dendrograms (latticeExtra)

Lauren Chong Lauren.Chong at oicr.on.ca
Tue Apr 3 19:31:46 CEST 2012


Hi,

I'm using the latticeExtra package's dendrogramGrob function to create a grob with both a dendrogram and a covariate bar (via the 'add' parameter). When the dendrogram has very short branches at its leaves, it appears as a line and becomes impossible to see when placed next to the covariate bar.

For example:
> x <- outer(-5:5, -5:5, "*") + matrix(nrow = 11, ncol = 11, data = runif(11 * 11));
> colnames(x) <- paste('col', 1:11, sep = '-');
> rownames(x) <- paste('row', 1:11, sep = '-');
>
> # Create some covariate data
> covariate.colours <- x[,1]
> covariate.colours[covariate.colours >= 0] <- "cornflowerblue";
> covariate.colours[covariate.colours != "cornflowerblue"] <- "coral";
> 
> covariates <-list(
+         rect = list(
+                 col = "black",
+                 fill = covariate.colours,
+                 lwd = 1.5
+                 )
+         );
> 
>
> # Cluster the data
> dd <- hclust(dist(x, method = "canberra"));
> dd <- as.dendrogram(dd);
>
> levelplot(
+ t(x),
+ scales = list(
+ x = list(
+ rot = 90
+ )
+ ),
+ colorkey = FALSE,
+ legend = list(
+ right = list(
+ fun = latticeExtra::dendrogramGrob,
+ args = list(
+ x = dd,
+ ord = order.dendrogram(dd),
+ side = "right",
+ size = 2.5,
+ size.add = 1,
+ add = covariates,
+ type = "rectangle"
+ )
+ )
+ )
+ );

In the resulting plot (attached as 'dendrogramGrob_covariates_example.png'), the bottom branches of the dendrogram are indistinguishable from the edge of the covariate bar.

I've been able to solve the problem by using my own version of dendrogramGrob that inserts a narrow extra grid column between the bar and the dendrogram in order to add whitespace (attached as 'dendrogramGrob_covariates_example_with_space.png'). Perhaps the actual dendrogramGrob function could be edited so that whitespace can be added between the rectangles and the dendrograms if desired?


> sessionInfo()
R version 2.14.2 (2012-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_CA.UTF-8        LC_COLLATE=en_CA.UTF-8    
 [5] LC_MONETARY=en_CA.UTF-8    LC_MESSAGES=en_CA.UTF-8   
 [7] LC_PAPER=C                 LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
[1] latticeExtra_0.6-20 RColorBrewer_1.0-5  lattice_0.20-6     

loaded via a namespace (and not attached):
[1] tools_2.14.2


Thanks, 
Lauren Chong
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dendrogramGrob_covariates_example.png
Type: image/png
Size: 217429 bytes
Desc: dendrogramGrob_covariates_example.png
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120403/025232e1/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dendrogramGrob_covariates_example_with_space.png
Type: image/png
Size: 219093 bytes
Desc: dendrogramGrob_covariates_example_with_space.png
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120403/025232e1/attachment-0003.png>


More information about the R-help mailing list