View source: R/scale_inferno.R
inferno_scale | R Documentation |
The inferno
color palette, by Nathaniel J. Smith and Stefan van der Walt (CC0 license).
inferno_scale( domain = c(0, 1), reverse = FALSE, na.value = NULL, extrapolate = FALSE ) inferno_map(x, ...) inferno_palette(...) inferno_colors(n, ...) scale_color_inferno_c( ..., reverse = FALSE, na.value = NULL, guide = "colorbar" ) scale_fill_inferno_c(..., reverse = FALSE, na.value = NULL, guide = "colorbar") scale_color_inferno_d(..., reverse = FALSE, na.value = NULL, guide = "legend") scale_fill_inferno_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
).
inferno
for the colors in the palette.
Other color scales and palettes:
brewer_scale()
,
chroma_scale()
,
cubehelix_scale()
,
etopo_scale()
,
hue_scale()
,
interp_scale()
,
light_scale()
,
magma_scale()
,
plasma_scale()
,
turbo_scale()
,
viridis_scale()
,
wikitopo_scale()
# Get a few colors along the palette show_col( inferno_palette()(20), inferno_colors(50), inferno_colors(20, reverse=TRUE) ) # 1/ Represent a continuous variable # Map the elevation of the Maunga Whau volcano image(maunga, col=inferno_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=inferno_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_inferno() # in spinning 3D library("rgl") persp3d(maunga, aspect=c(1,0.7,0.2), axes=FALSE, box=FALSE, col=inferno_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 <- inferno_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_inferno() ggplot(airquality) + theme_dark() + geom_point(aes(x=Wind, y=Temp, color=Ozone)) + scale_color_inferno(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=inferno_map(Species)) sidelegend(legend=levels(Species), pt.bg=inferno_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_inferno_d() ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.