colourscale: colourscale

Description Usage Arguments Examples

View source: R/colourscale.R

Description

generate a colour scale for plotting scales with a variable number states.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
colorscale(n, col = NULL, ...)

## S3 method for class 'factor'
colourscale(factor, col = NULL, colours = NULL, colors = NULL)

## S3 method for class 'character'
colourscale(character, col = NULL, colours = NULL, colors = NULL)

## S3 method for class 'numeric'
colourscale(vector, col = NULL, colours = NULL, colors = NULL)

## Default S3 method:
colourscale(n, col = NULL, colours = NULL, colors = NULL)

Arguments

n

number of colours to generate (integer or numeric)

col, colour, color

scale of colours to interpolate

Examples

 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
# generate colour scale
library("RColorBrewer")
colours <- brewer.pal(11, "Set3")
n <- 3
scale <- colourscale(n, colours)
# example plot
x_mean <- rnorm(n, 1000, 500)
y_mean <- rnorm(n, 1000, 500)
x_vals <- sapply(x_mean, function(x) rnorm(100, x, 50))
y_vals <- sapply(y_mean, function(y) rnorm(100, y, 50))
plot(x_vals, y_vals, col = scale[unlist(lapply(1:n, function(x) rep(x, 100)))], pch = 20)
legend("topleft", legend = 1:n, col = scale, pch = 20)

# generate colour scale
library("RColorBrewer")
colours <- brewer.pal(11, "Set3")
n <- 15
scale <- colourscale(n, colours)
# example plot
x_mean <- rnorm(n, 1000, 500)
y_mean <- rnorm(n, 1000, 500)
x_vals <- sapply(x_mean, function(x) rnorm(100, x, 50))
y_vals <- sapply(y_mean, function(y) rnorm(100, y, 50))
plot(x_vals, y_vals, col = scale[unlist(lapply(1:n, function(x) rep(x, 100)))], pch = 20)
legend("topleft", legend = 1:n, col = scale, pch = 20)

TomKellyGenetics/tktools documentation built on Dec. 13, 2021, 10:06 p.m.