dendrogramGrob {latticeExtra}R Documentation

Create a Grob Representing a Dendrogram

Description

This function creates a grob (a grid graphics object) that can be manipulated as such. In particular, it can be used as a legend in a lattice display like levelplot to form heatmaps.

Usage

dendrogramGrob(x, ord = order.dendrogram(x),
               side = c("right", "top"),
               add = list(), size = 5, size.add = 1,
               type = c("rectangle", "triangle"),
               ...)

Arguments

x An object of class "dendrogram". See dendrogram for details
ord A vector of integer indices giving the order in which the terminal leaves are to be plotted. If this is not the same as order.dendrogram(x), then the leaves may not cluster together and branches of the dendrogram may intersect.
side Intended position of the dendrogram when added in a heatmap. Currently allowed positions are "right" and "top".
add Additional annotation. Currently, it is only possible to add one or more rows of rectangles at the base of the dendrogram. See details below.
size Total height of the dendrogram in "lines" (see unit)
size.add Size of each additional row, also in "lines"
type Whether a child node is joined to its parent directly with a straight line ("triangle") or as a “stair” with two lines ("rectangle")
... Extra arguments. Currently ignored.

Details

The add argument can be used for additional annotation at the base of the dendrogram. It should be a list with one component for each row, with names specifying the type of annotation and components specifying the contents. Currently, the only supported name is "rect" (which can be repeated), producing rectangles. The components in such a case is a list of graphical parameters, possibly vectorized, that are passed on to gpar.

Value

An object of class "grob"

Author(s)

Deepayan Sarkar

See Also

heatmap, levelplot

Alias

dendrogramGrob

Keyword

dplot

Examples


data(mtcars)
x  <- t(as.matrix(scale(mtcars)))
dd.row <- as.dendrogram(hclust(dist(x)))
row.ord <- order.dendrogram(dd.row)

dd.col <- as.dendrogram(hclust(dist(t(x))))
col.ord <- order.dendrogram(dd.col)

library(lattice)

levelplot(x[row.ord, col.ord],
          aspect = "fill",
          scales = list(x = list(rot = 90)),
          colorkey = list(space = "left"),
          legend =
          list(right =
               list(fun = dendrogramGrob,
                    args =
                    list(x = dd.col, ord = col.ord,
                         side = "right",
                         size = 10)),
               top =
               list(fun = dendrogramGrob,
                    args =
                    list(x = dd.row, 
                         side = "top",
                         type = "triangle"))))

levelplot(x[, col.ord],
          aspect = "iso",
          scales = list(x = list(rot = 90)),
          colorkey = FALSE,
          legend =
          list(right =
               list(fun = dendrogramGrob,
                    args =
                    list(x = dd.col, ord = col.ord,
                         side = "right",
                         size = 10)),
               top =
               list(fun = dendrogramGrob,
                    args =
                    list(x = dd.row, ord = sort(row.ord),
                         side = "top", size = 10,
                         type = "triangle"))))

Results


R version 2.9.0 (2009-04-17)
Copyright (C) 2009 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(latticeExtra)
> png(filename="images/dendrogramGrob_%03d.png" ,width=480, height=480)
> ### Name: dendrogramGrob
> ### Title: Create a Grob Representing a Dendrogram
> ### Aliases: dendrogramGrob
> ### Keywords: dplot
> 
> ### ** Examples
> 
> 
> data(mtcars)
> x  <- t(as.matrix(scale(mtcars)))
> dd.row <- as.dendrogram(hclust(dist(x)))
> row.ord <- order.dendrogram(dd.row)
> 
> dd.col <- as.dendrogram(hclust(dist(t(x))))
> col.ord <- order.dendrogram(dd.col)
> 
> library(lattice)
> 
> levelplot(x[row.ord, col.ord],
+           aspect = "fill",
+           scales = list(x = list(rot = 90)),
+           colorkey = list(space = "left"),
+           legend =
+           list(right =
+                list(fun = dendrogramGrob,
+                     args =
+                     list(x = dd.col, ord = col.ord,
+                          side = "right",
+                          size = 10)),
+                top =
+                list(fun = dendrogramGrob,
+                     args =
+                     list(x = dd.row, 
+                          side = "top",
+                          type = "triangle"))))
> 
> levelplot(x[, col.ord],
+           aspect = "iso",
+           scales = list(x = list(rot = 90)),
+           colorkey = FALSE,
+           legend =
+           list(right =
+                list(fun = dendrogramGrob,
+                     args =
+                     list(x = dd.col, ord = col.ord,
+                          side = "right",
+                          size = 10)),
+                top =
+                list(fun = dendrogramGrob,
+                     args =
+                     list(x = dd.row, ord = sort(row.ord),
+                          side = "top", size = 10,
+                          type = "triangle"))))
> 
> 
> 
> 
> dev.off()
null device 
          1 
> 



[Package latticeExtra Index]