Description Usage Arguments Details Value Author(s) See Also Examples
View source: R/dendrogramGrob.R
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.
1 2 3 4 5 | dendrogramGrob(x, ord = order.dendrogram(x),
side = c("right", "top"),
add = list(), size = 5, size.add = 1,
type = c("rectangle", "triangle"),
...)
|
x |
An object of class |
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
|
side |
Intended position of the dendrogram when added in a
heatmap. Currently allowed positions are |
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 |
size.add |
Size of each additional row, also in |
type |
Whether a child node is joined to its parent directly
with a straight line ( |
... |
Extra arguments. Currently ignored. |
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
.
An object of class "grob"
Deepayan Sarkar deepayan.sarkar@r-project.org
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | 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"))))
## Version with unsorted rows.
## For illustration, MPG ploted again at foot of dendrogram
mpg <- x["mpg", col.ord]
mpg.col <- level.colors(mpg, at = do.breaks(range(mpg), 10),
col.regions = terrain.colors)
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",
add = list(rect = list(fill = mpg.col)),
size = 10)),
top =
list(fun = dendrogramGrob,
args =
list(x = dd.row, ord = sort(row.ord),
side = "top", size = 10,
type = "triangle"))))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.