Title: | Colour Palettes for Data |
---|---|
Description: | Colour palettes for data, based on some well known public data sets. Includes helper functions to map absolute values to known palettes, and capture the work of image colour mapping as raster data sets. |
Authors: | Michael D. Sumner [aut, cre], Abigael Proctor [ctb] (Named the package), Tomas Remenyi [ctb] (Provided colours for element_pal), R Core Team and contributors worldwide [ctb] (source code of image.default) |
Maintainer: | Michael D. Sumner <[email protected]> |
License: | GPL-3 |
Version: | 0.4.0 |
Built: | 2024-11-12 05:57:53 UTC |
Source: | https://github.com/AustralianAntarcticDivision/palr |
Deep bathymetry colours.
bathy_deep_pal(x, palette = FALSE, alpha = 1, ...) bathyDeepPal(x, palette = FALSE, alpha = 1, ...)
bathy_deep_pal(x, palette = FALSE, alpha = 1, ...) bathyDeepPal(x, palette = FALSE, alpha = 1, ...)
x |
a vector of data values or a single num (n) |
palette |
logical, if |
alpha |
value in 0,1 to specify opacity |
... |
currently ignored |
Colour ramp suitable for deep waters (-5500) to sea level. The palette functions operate in 3 modes: 1) n colours - Pal(6) - returns 6 colours from the palette 2) data - Pal(c(10, 50, 100)) - return colours for 3 ice concentrations 3) palette - Pal(palette = TRUE) - return the full palette and breaks Derived from maps created in Matlab by Emmanuel Laurenceau.
colours, palette, or function, see Details
plot(1:15, pch = 19, cex = 4, col = bathy_deep_pal(15))
plot(1:15, pch = 19, cex = 4, col = bathy_deep_pal(15))
Ocean colour palette for chlorophyll-a.
chl_pal(x, palette = FALSE, alpha = 1) chlPal(x, palette = FALSE, alpha = 1, ...)
chl_pal(x, palette = FALSE, alpha = 1) chlPal(x, palette = FALSE, alpha = 1, ...)
x |
a vector of data values or a single number |
palette |
logical, if |
alpha |
value in 0,1 to specify opacity |
... |
currently unused |
Flexible control of the chlorophyll-a palette. If x
is a
single number, the function returns that many colours evenly
spaced from the palette. If x
is a vector of multiple
values the palette is queried for colours matching those values,
and these are returned. If x
is missing and palette
is FALSE
then a function is returned that will generate n
evenly spaced colours from the palette, as per
colorRampPalette
.
colours, palette, or function, see Details
Derived from a file once found at 'http://oceancolor.gsfc.nasa.gov/DOCS/palette_chl_etc.txt'
## Not run: chl <- raadtools::readchla(xylim = c(100, 110, -50, -40)) ## just get a small number of evenly space colours plot(chl, col = chl_pal(10)) ## store the full palette and work with values and colours pal <- chl_pal() ## the standard full palette plot(chl, breaks = pal$breaks, col = pal$cols) ## a custom set of values with matching colours plot(chl, col = chl_pal(pal$breaks[seq(1, length(pal$breaks), length = 10)])) ## any number of colours stored as a function myfun <- chl_pal() plot(chl, col = myfun(18)) ## just n colours plot(chl, col = chl_pal(18)) ## End(Not run)
## Not run: chl <- raadtools::readchla(xylim = c(100, 110, -50, -40)) ## just get a small number of evenly space colours plot(chl, col = chl_pal(10)) ## store the full palette and work with values and colours pal <- chl_pal() ## the standard full palette plot(chl, breaks = pal$breaks, col = pal$cols) ## a custom set of values with matching colours plot(chl, col = chl_pal(pal$breaks[seq(1, length(pal$breaks), length = 10)])) ## any number of colours stored as a function myfun <- chl_pal() plot(chl, col = myfun(18)) ## just n colours plot(chl, col = chl_pal(18)) ## End(Not run)
Create colours from colour names in one easy step.
col2hex(x, alpha = 1)
col2hex(x, alpha = 1)
x |
vector of colour names or hex strings |
alpha |
optional transparency value in [0,1], can be per colour in |
character string of hex colours
col2hex(c("aliceblue", "firebrick"), alpha = c(1, .5)) col2hex(c("#FFFFFF", "#123456FF"), alpha = 0.1)
col2hex(c("aliceblue", "firebrick"), alpha = c(1, .5)) col2hex(c("#FFFFFF", "#123456FF"), alpha = 0.1)
Scales input data to the palette, so that colour is mapped linearly to the range of values.
d_pal(x, pal = hcl.colors(84)) data_pal(x, pal = hcl.colors(84))
d_pal(x, pal = hcl.colors(84)) data_pal(x, pal = hcl.colors(84))
x |
data vector, maybe be numeric or character |
pal |
palette, may be colours or a function |
Default palette 'pal' is the 'viridis' colours of [grDevices::hcl.colors()], and may be literal colour values or a function.
[data_pal()] is an alias of [d_pal()].
plot(1:100, col = d_pal(1:100)) plot(1:100, col = d_pal(1:100, chl_pal))
plot(1:100, col = d_pal(1:100)) plot(1:100, col = d_pal(1:100, chl_pal))
Convert list of raster output to bathymetry palette
dirty_image(x, alpha = 1)
dirty_image(x, alpha = 1)
x |
object returned by vapour package 'gdal_raster_data()' |
alpha |
0 to 1 for transparency |
modified x
From AAD underway facility.
dirty_pal(x, alpha = 1)
dirty_pal(x, alpha = 1)
x |
numeric value |
alpha |
0 to 1 for transparency |
vector of hex colours
dirty_pal(seq(-8000, 0, length.out = 10))
dirty_pal(seq(-8000, 0, length.out = 10))
Colours for sea ice.
ice_pal(x, palette = FALSE, alpha = 1, ..., amsre = FALSE) icePal(x, palette = FALSE, alpha = 1, ...)
ice_pal(x, palette = FALSE, alpha = 1, ..., amsre = FALSE) icePal(x, palette = FALSE, alpha = 1, ...)
x |
a vector of data values or a single num (n) |
palette |
logical, if |
alpha |
value in 0,1 to specify opacity |
... |
currently ignored |
amsre |
use old AMSRE colours ('FALSE' by default) |
The palette functions operate in 3 modes: 1) n colours - Pal(6) - returns 6 colours from the palette 2) data - Pal(c(10, 50, 100)) - return colours for 3 ice concentrations 3) palette - Pal(palette = TRUE) - return the full palette and breaks
colours, palette, or function, see Details
amsre colours derived from http://www.iup.uni-bremen.de/seaice/amsr/., nsidc colours extracted in data-raw/.
## Not run: library(raster) r <- raster(system.file("extdata", "nt_20140320_f17_v01_s.bin", package = "graticule") ) icp <- ice_pal(palette = TRUE) ## The AMSR colours plot(r, col = icp$col, zlim = range(icp$breaks), main = sprintf("NSIDC ice \\% %s", format(getZ(r)))) ## End(Not run)
## Not run: library(raster) r <- raster(system.file("extdata", "nt_20140320_f17_v01_s.bin", package = "graticule") ) icp <- ice_pal(palette = TRUE) ## The AMSR colours plot(r, col = icp$col, zlim = range(icp$breaks), main = sprintf("NSIDC ice \\% %s", format(getZ(r)))) ## End(Not run)
If no 'col' is provided, the default image palette is used. The density can be controlled with 'n' and the mapping with the optional 'breaks'. If 'breaks' is included as well as 'n', 'n' is ignored.
image_pal(x, col, ..., breaks = NULL, n = NULL, zlim = NULL) image_raster(x, col, ..., breaks = NULL, n = NULL, zlim = NULL) image_stars(x, col, ..., breaks = NULL, n = NULL, zlim = NULL)
image_pal(x, col, ..., breaks = NULL, n = NULL, zlim = NULL) image_raster(x, col, ..., breaks = NULL, n = NULL, zlim = NULL) image_stars(x, col, ..., breaks = NULL, n = NULL, zlim = NULL)
x |
numeric values, raster object (single layer only) or stars object (single variable, 2D array only) |
col |
function to generate colours, or a vector of hex colours |
... |
ignored |
breaks |
optionally used to specify colour mapping |
n |
optionally used to specify density of colours from 'col' (ignored if 'breaks' is set) |
zlim |
numeric range to clamp values to an absolute scale (ignored if 'breaks' is set) |
The function 'image_pal()' only returns hex character string colours. The function 'image_raster()' will map a raster of numeric values to an RGB 3-layer (channel) raster brick, and 'image_stars()' similarly for a 3-dimensional stars object.
Please note that the expansion to 3-channels is a fairly wasteful thing to do, the overall data is expanded from a single layer to three but this faciliates a specific task of creating textures for 3D mapping, and this is the only way to do it currently. It's also useful in other situations, for controlling exactly the kind of plots we can achieve and for exporting to image formats such as 'GeoTIFF' or 'PNG'.
for 'image_pal()' a vector of hex colours, for 'image_raster' and 'image_stars' a raster or stars object with 3 channel RGB (range 0,255)
vals <- sort(rnorm(100)) cols <- image_pal(vals, zlim = c(-2.4, .5)) plot(vals, col = cols); abline(h = .5) points(vals, pch = ".") ## zlim excluded some of the range
vals <- sort(rnorm(100)) cols <- image_pal(vals, zlim = c(-2.4, .5)) plot(vals, col = cols); abline(h = .5) points(vals, pch = ".") ## zlim excluded some of the range
Create a time-indexed colour map, useful for maintaining an absolute scale across time series as a function of date-time.
mk_timePal(x, col)
mk_timePal(x, col)
x |
date-times |
col |
colours, can be a function or an actual set of colours |
function of date-time
dts <- seq(as.Date("1749-01-01"), by = "1 month", length.out = length(sunspots)) d <- data.frame(date = dts, sunspots = as.vector(t(sunspots))) tpal <- mk_timePal(d$date, col = sst_pal(50)) par(mfrow = c(2, 1)) plot(sunspots ~ date, col = tpal(date), data = d) ## colours maintained by absolute date plot(sunspots ~ date, col = tpal(date), data = d[1500:1800, ], cex = 2) ## we can now insert new points and maintain this colour ramp d2 <- data.frame(date = seq(min(d$date), max(d$date), by = "5 days")) d2$sunspots <- approxfun(d$date, d$sunspots)(d2$date) points(sunspots ~ date, col = tpal(date), data = d2, pch = 19, cex = 0.5)
dts <- seq(as.Date("1749-01-01"), by = "1 month", length.out = length(sunspots)) d <- data.frame(date = dts, sunspots = as.vector(t(sunspots))) tpal <- mk_timePal(d$date, col = sst_pal(50)) par(mfrow = c(2, 1)) plot(sunspots ~ date, col = tpal(date), data = d) ## colours maintained by absolute date plot(sunspots ~ date, col = tpal(date), data = d[1500:1800, ], cex = 2) ## we can now insert new points and maintain this colour ramp d2 <- data.frame(date = seq(min(d$date), max(d$date), by = "5 days")) d2$sunspots <- approxfun(d$date, d$sunspots)(d2$date) points(sunspots ~ date, col = tpal(date), data = d2, pch = 19, cex = 0.5)
SST example raster data set, at 0.25 degree resolution for global coverage in "longitude180/latitude".
Created using script in data-raw/ using 'raadtools' package.
Reynolds, et al.(2007) Daily High-resolution Blended Analyses. Available from 'NOAA' search for 'OISST'.
Climatology is based on 1971-2000 OI.v2 SST, Satellite data: Navy NOAA19 METOP AVHRR, Ice data: #' NCEP ice Source: NOAA/National Climatic Data Center.
dim(oisst) class(oisst) image(oisst, useRaster = TRUE)
dim(oisst) class(oisst) image(oisst, useRaster = TRUE)
palr: colours for data
Maintainer: Michael D. Sumner [email protected]
Other contributors:
Abigael Proctor (Named the package) [contributor]
Tomas Remenyi (Provided colours for element_pal) [contributor]
R Core Team and contributors worldwide (source code of image.default) [contributor]
Useful links:
Report bugs at https://github.com/AustralianAntarcticDivision/palr/issues
SST colours
sst_pal(x, palette = FALSE, alpha = 1, ...) sstPal(x, palette = FALSE, alpha = 1, ...)
sst_pal(x, palette = FALSE, alpha = 1, ...) sstPal(x, palette = FALSE, alpha = 1, ...)
x |
a vector of data values or a single number |
palette |
logical, if |
alpha |
value in 0,1 to specify opacity |
... |
currently ignored |
colours, palette, or function, see Details
Derived from a file once found at 'http://oceancolor.gsfc.nasa.gov/DOCS/palette_sst.txt'
data(oisst) sstcols <- sst_pal(palette = TRUE) image(oisst, col = sstcols$col, zlim = range(sstcols$breaks))
data(oisst) sstcols <- sst_pal(palette = TRUE) image(oisst, col = sstcols$col, zlim = range(sstcols$breaks))