turbo_scale | R Documentation |
The turbo
color palette, by Anton Mikhailov (Apache-2.0 license).
turbo_scale( domain = c(0, 1), reverse = FALSE, na.value = NULL, extrapolate = FALSE ) turbo_map(x, ...) turbo_palette(...) turbo_colors(n, ...) scale_color_turbo_c(..., reverse = FALSE, na.value = NULL, guide = "colorbar") scale_fill_turbo_c(..., reverse = FALSE, na.value = NULL, guide = "colorbar") scale_color_turbo_d(..., reverse = FALSE, na.value = NULL, guide = "legend") scale_fill_turbo_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
).
turbo
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()
,
plasma_scale()
,
viridis_scale()
,
wikitopo_scale()
# Get a few colors along the palette show_col( turbo_palette()(20), turbo_colors(50), turbo_colors(20, reverse=TRUE) ) # 1/ Represent a continuous variable # Map the elevation of the Maunga Whau volcano image(maunga, col=turbo_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=turbo_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_turbo() # in spinning 3D library("rgl") persp3d(maunga, aspect=c(1,0.7,0.2), axes=FALSE, box=FALSE, col=turbo_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 <- turbo_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 ggplot(airquality) + geom_point(aes(x=Wind, y=Temp, fill=Ozone), shape=21, size=2) + scale_fill_turbo() ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.