colourscale | R Documentation |
generate a colour scale for plotting scales with a variable number states.
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)
n |
number of colours to generate (integer or numeric) |
col , colour , color |
scale of colours to interpolate |
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.