Legend {ComplexHeatmap} | R Documentation

## Making legend grobs

### Description

Making legend grobs

### Usage

    Legend(at, labels = at, nrow = NULL, ncol = 1, col_fun, by_row = FALSE,
        grid_height = unit(4, "mm"), grid_width = unit(4, "mm"), gap = unit(2, "mm"),
        labels_gp = gpar(fontsize = 10),
        border = NULL, background = "#EEEEEE",
        type = "grid", legend_gp = gpar(),
        pch = 16, size = unit(2, "mm"),
        legend_height = NULL, legend_width = NULL,
        direction = c("vertical", "horizontal"),
        title = "", title_gp = gpar(fontsize = 10, fontface = "bold"),
        title_position = c("topleft", "topcenter", "leftcenter", "lefttop"))

### Arguments

`at` | breaks, can be wither numeric or character
`labels` | labels corresponding to `at`
`nrow` | if there are too many legends, they can be positioned in an array, this controls number of rows
`ncol` | if there are too many legends, they can be positioned in an array, this controls number of columns. At a same time only one of `nrow` and `ncol` can be specified.
`col_fun` | a color mapping function which is used to make a continuous color bar
`by_row` | when there are multiple columns for legends, whether to arrange them by rows.
`grid_height` | height of legend grid
`grid_width` | width of legend grid
`gap` | when legends are put in multiple columns, this is the gap between neighbouring columns, measured as a `unit` object
`labels_gp` | graphic parameters for labels
`border` | color of legend borders, also for the ticks in the continuous legend
`background` | background colors
`type` | type of legends, can be `grid`, `points` and `lines`
`legend_gp` | graphic parameters for the legend
`pch` | type of points
`size` | size of points
`legend_height` | height of the whole legend, used when `col_fun` is specified and `direction` is set to `vertical`
`legend_width` | width of the whole legend, used when `col_fun` is specified and `direction` is set to `horizontal`
`direction` | direction of the continuous or discrete legend
`title` | title of the legend
`title_gp` | graphic parameters of title
`title_position` | position of title according to the legend

### Value

A `grob` object

### See Also

`packLegend` packs multiple legends into one `grob` object

### Examples

    lgd = Legend(title = "discrete", at = 1:4, labels = letters[1:4],
    	legend_gp = gpar(fill = 2:5))
    grid.newpage()
    grid.draw(lgd)

    require(circlize)
    col_fun = colorRamp2(c(-1, 0, 1), c("blue", "white", "red"))
    lgd = Legend(title = "continuous", at = seq(-1, 1, by = 0.5), col_fun = col_fun)
    grid.newpage()
    grid.draw(lgd)

    lgd = Legend(title = "continuous", at = seq(-1, 1, by = 0.5), col_fun = col_fun,
    	direction = "horizontal")
    grid.newpage()
    grid.draw(lgd)

    lgd = Legend(title = "discrete", at = 1:10, labels = letters[1:10],
    	ncol = 4, by_row = TRUE, legend_gp = gpar(fill = rand_color(10)))
    grid.newpage()
    grid.draw(lgd)

    lgd = Legend(title = "lty", at = 1:3, labels = 1:3, type = "lines",
    	legend_gp = gpar(lty = 1:3))
    grid.newpage()
    grid.draw(lgd)

[Package ComplexHeatmap version 1.20.0 Index]