Skip to contents

assigns colors to continuous or categorical values for plotting

Usage

tectonicr.colors(
  x,
  n = 10,
  pal = NULL,
  categorical = FALSE,
  na.value = "grey",
  ...
)

Arguments

x

values for color assignment

n

integer. number of colors for continuous colors (i.e. `categorical = FALSE``).

pal

either a named vector specifying the colors for categorical values, or a color function. If NULL, default colors are RColorBrewer::brewer.pal() (categorical = TRUE) and viridis::viridis() (categorical = FALSE).

categorical

logical.

na.value

color for NA values (categorical).

...

optional arguments passed to palette function

Value

named color vector

Examples

val1 <- c("N", "S", "T", "T", NA)
tectonicr.colors(val1, categorical = TRUE)
#> Joining with `by = join_by(val)`
#>         N         S         T         T      <NA> 
#> "#66C2A5" "#FC8D62" "#8DA0CB" "#8DA0CB" "#E78AC3" 
tectonicr.colors(val1, pal = stress_colors(), categorical = TRUE)
#> Joining with `by = join_by(val)`
#>         N         S         T         T      <NA> 
#> "#D55E00" "#009E73" "#0072B2" "#0072B2"    "grey" 

val2 <- runif(10)
tectonicr.colors(val2, n = 5)
#>   [0.1,0.2]   (0.7,0.8]   (0.2,0.3]   [0.1,0.2]   (0.5,0.6]   (0.4,0.5] 
#> "#440154FF" "#FDE725FF" "#443A83FF" "#440154FF" "#35B779FF" "#21908CFF" 
#>   (0.6,0.7]   (0.2,0.3]   (0.6,0.7]   (0.3,0.4] 
#> "#8FD744FF" "#443A83FF" "#8FD744FF" "#31688EFF"