plasma_scale | R Documentation |
The plasma
color palette, by Nathaniel J. Smith and Stefan van der Walt (CC0 license).
plasma_scale(
domain = c(0, 1),
reverse = FALSE,
na.value = NULL,
extrapolate = FALSE
)
plasma_map(x, ...)
plasma_palette(...)
plasma_colors(n, ...)
scale_color_plasma_c(..., reverse = FALSE, na.value = NULL, guide = "colorbar")
scale_fill_plasma_c(..., reverse = FALSE, na.value = NULL, guide = "colorbar")
scale_color_plasma_d(..., reverse = FALSE, na.value = NULL, guide = "legend")
scale_fill_plasma_d(..., reverse = FALSE, na.value = NULL, guide = "legend")
domain |
vector of two values between which the scale is computed. |
reverse |
whether to reverse the order of colors along the scale. |
na.value |
value to return for missing values in the input. Can be either a color, |
extrapolate |
when |
x |
a vector whose values will be coerced to numbers and mapped to colors. |
... |
passed to |
n |
number of colors to extract from the color palette. |
guide |
type of guide for the legend ("colorbar" for a continuous colorbar, "legend" for a categorical guide) or guide object itself. |
*_scale
returns a function. This function takes a single argument (x
: a numeric vector), maps its values to colors, and returns thee colors as hex codes.
*_map
is a shortcut for *_scale(domain=range(x))(x)
: it creates a scale that spans the range of values in argument x
, maps the content of x
on that scale, and returns the colors.
*_palette
returns a function. This function takes an integer (n
) as argument, picks n
colors evenly spaced along the scale, and returns them as hex codes.
*_colors
is a shortcut for *_palette()(n)
and directly returns n
evenly spaced colors. It is equivalent to built-in functions such as heat.colors
, topo.colors
, etc.
scale_*
return a ggplot2 scale, either discrete (similar to scale_color_discrete
) or continuous (similar to scale_color_continuous
).
plasma
for the colors in the palette.
Other color scales and palettes:
brewer_scale()
,
chroma_scale()
,
cubehelix_scale()
,
etopo_scale()
,
hue_scale()
,
inferno_scale()
,
interp_scale()
,
light_scale()
,
magma_scale()
,
turbo_scale()
,
viridis_scale()
,
vsup_scale()
,
wikitopo_scale()
# Get a few colors along the palette
show_col(
plasma_palette()(20),
plasma_colors(50),
plasma_colors(20, reverse=TRUE)
)
# 1/ Represent a continuous variable
# Map the elevation of the Maunga Whau volcano
image(maunga, col=plasma_colors(100), asp=1)
contour(maunga, col=alpha("white", 0.5), add=TRUE)
persp(maunga, theta=50, phi=25, scale=FALSE, expand=2,
border=alpha("black", 0.4),
col=plasma_map(persp_facets(maunga$z)))
## Not run:
# with ggplot2
library("ggplot2")
ggplot(maungaxyz) + coord_fixed() +
geom_raster(aes(x=x, y=y, fill=z)) +
geom_contour(aes(x=x, y=y, z=z), color="white", alpha=0.5) +
scale_fill_plasma()
# in spinning 3D
library("rgl")
persp3d(maunga, aspect=c(1,0.7,0.2), axes=FALSE, box=FALSE,
col=plasma_map(maunga$z))
play3d(spin3d(axis=c(0, 0, 1), rpm=10), duration=6)
## End(Not run)
# Represent a third variable on a scatterplot
attach(airquality)
# define a scale encompassing the whole data
my_scale <- plasma_scale(domain=c(0,200))
# use the same scale for the plot and the legend
pars <- sidemargin()
plot(Wind, Temp, col=my_scale(Ozone), pch=19)
sidelegend(legend=c(pretty(Ozone), "NA"),
col=my_scale(c(pretty(Ozone), NA)), pch=19)
par(pars)
## Not run:
# or with ggplot2
# but the light yellows at the top of the scale are difficult to see
# on points; either outline them or put them on a dark background
ggplot(airquality) +
geom_point(aes(x=Wind, y=Temp, fill=Ozone), shape=21, size=2) +
scale_fill_plasma()
ggplot(airquality) + theme_dark() +
geom_point(aes(x=Wind, y=Temp, color=Ozone)) +
scale_color_plasma(na.value="grey60")
## End(Not run)
# 2/ Represent a discrete variable
# albeit only with a limited number of levels
attach(iris)
pars <- sidemargin()
plot(Petal.Length, Petal.Width, pch=21, bg=plasma_map(Species))
sidelegend(legend=levels(Species),
pt.bg=plasma_colors(n=nlevels(Species)), pch=21)
par(pars)
## Not run:
# or with ggplot2
ggplot(iris) +
geom_point(aes(Petal.Length, Petal.Width, fill=Species), shape=21) +
scale_fill_plasma_d()
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.