getColours | R Documentation |
Get some nice colours
getColours(Ncols, continuous = FALSE, Dcols = c(0, 1))
Ncols |
Either an integer representing the number of requested colours, or, a numeric vector of integers between 1-58 to select specific colours. Run |
continuous |
Return a discrete vector of colours, or, a function that represents a gradient between 2 or more colours? If |
Dcols |
If |
A list of colours
# This will plot all available colours with their numbers
getColours()
# Get a specific number of colours
getColours(5)
# Get specific colours
getColours(c(4,7,1,40))
# Make a gradient from colour number 4 to 44 via 7
gradFunc <- getColours(Ncols = c(4,7,44), continuous = TRUE, Dcols = c(0,.5,1))
df <- data.frame(x=1:50, y=sort(rnorm(50)))
# Make sure the input is on a scale of 0-1
df$ycol <- elascer(df$y)
library(ggplot2)
ggplot(df, aes(x=x,y=y,colour=ycol)) +
geom_point() +
scale_colour_gradientn("Gradient",colours = gradFunc(df$ycol)) +
theme_bw()
# Make a gradient from colour number 4, to 9, to 7, to 36, to 44
gradFunc <- getColours(Ncols = c(4,9,7,36,44), continuous = TRUE, Dcols = c(0,.33,.5,.66,1))
ggplot(df, aes(x=x,y=y,colour=ycol)) +
geom_point() +
scale_colour_gradientn("Gradient",colours = gradFunc(df$ycol)) +
theme_bw()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.