map2color: Maps numeric values to color values

Description Usage Arguments Value Examples

View source: R/GeneTonic-extras.R

Description

Maps numeric continuous values to values in a color palette

Usage

1
map2color(x, pal, limits = NULL)

Arguments

x

A character vector of numeric values (e.g. log2FoldChange values) to be converted to a vector of colors

pal

A vector of characters specifying the definition of colors for the palette, e.g. obtained via brewer.pal

limits

A vector containing the limits of the values to be mapped. If not specified, defaults to the range of values in the x vector.

Value

A vector of colors, each corresponding to an element in the original vector

Examples

1
2
3
4
5
6
7
8
9
a <- 1:9
pal <- RColorBrewer::brewer.pal(9,"Set1")
map2color(a, pal)
plot(a, col = map2color(a, pal), pch = 20, cex = 4)

b <- 1:50
pal2 <- grDevices::colorRampPalette(
  RColorBrewer::brewer.pal(name = "RdYlBu", 11))(50)
plot(b, col = map2color(b, pal2), pch = 20, cex = 3)

GeneTonic documentation built on Nov. 8, 2020, 5:27 p.m.