etopo_scale: ETOPO1 scale and palette

View source: R/scale_etopo.R

etopo_scaleR Documentation

ETOPO1 scale and palette

Description

Color scale and palette inspired from the representation of the ETOPO1 global relief model. These scales are special because the mapping between colors and values is predefined to work for altitudes (or depths when the numbers are negative).

Usage

etopo_scale(na.value = NULL)

etopo_map(x, ...)

etopo_palette(...)

etopo_colors(n, ...)

scale_fill_etopo(na.value = NULL, ...)

scale_color_etopo(na.value = NULL, ...)

Arguments

na.value

value to return for missing values in the input. Can be either a color, NULL in which case a tentitatively appropriate color will be chosen automatically, or NA.

x

a vector whose values will be coerced to numbers and mapped to colors.

...

passed to etopo_scale or to scale_*_gradientn for the scale_*_etopo functions.

n

number of colors to extract from the color palette.

Value

*_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).

References

The topographic colors are based on GMT globe by Lester M. Anderson of CASP, UK, modified by Jesse Varner and Elliot Lim (NOAA/NGDC) to have a smaller band of white at the highest elevations. The bathymetry is based on GMT haxby, popularised by Bill Haxby, LDEO. See https://www.ngdc.noaa.gov/mgg/global/global.html.

See Also

etopo for the colors in the palette and the associated altitudes.

Other color scales and palettes: brewer_scale(), chroma_scale(), cubehelix_scale(), hue_scale(), inferno_scale(), interp_scale(), light_scale(), magma_scale(), plasma_scale(), turbo_scale(), viridis_scale(), wikitopo_scale()

Examples

# Defining a scale in that case has little value since it cannot be
# customized. Explore the default mapping
altitudes <- c(-5000, -1000, -10, 0, 10, 200, 500, 5000)
show_col(etopo_map(altitudes))
# Explore the full range of colors
show_col(etopo_map(seq(-8000, 8000, length=500)))

# It is possible to get n colors from the palette but they loose their
# association with specific altitudes
etopo_colors(5)

# The goal of these scales is to color maps and elevation models. Here is
# one centered on Thailand, showcasing high mountains and deep trenches
levs <- seq(-9000, 6000, by=500)
contour(thai, levels=levs, col=etopo_map(levs), asp=1.03)

filled.contour(thai, levels=levs, col=etopo_map(levs), asp=1.03)

persp(thai, theta=30, phi=25, border=alpha("black", 0.2), expand=0.2,
      col=etopo_map(persp_facets(thai$z)))

## Not run: 
# in spinning 3D
library("rgl")
persp3d(thai, aspect=c(1,0.96,0.2), axes=FALSE, box=FALSE,
        col=etopo_map(thai$z))
play3d(spin3d(axis=c(0, 0, 1), rpm=10), duration=6)

# or with ggplot2
library("ggplot2")
ggplot(thaixyz) + coord_quickmap() +
  geom_contour(aes(x, y, z=z, color=..level..), breaks=levs) +
  theme_light() + scale_color_etopo() + scale_xy_map()
ggplot(thaixyz) + coord_quickmap() +
  geom_raster(aes(x, y, fill=z)) +
  scale_fill_etopo() + scale_xy_map() +
  geom_contour(aes(x, y, z=z), breaks=0, color="black", size=1) 
## End(Not run)

jiho/chroma documentation built on Nov. 26, 2022, 2:39 a.m.