default.colourmap: Default Colour Map for Plotting a Spatial Pattern

View source: R/colourtables.R

default.colourmapR Documentation

Default Colour Map for Plotting a Spatial Pattern

Description

Determines a colour map for plotting a spatial pattern (or other data) when one is not supplied by the user.

Usage

default.colourmap(x, ...,
                  col=spatstat.options("image.colfun"),
                  scramble.cols=FALSE,
                  monochrome=spatstat.options("monochrome"))

Arguments

x

A vector of atomic values, or a factor.

col

Optional. A specification of colours to be used. See Details.

scramble.cols

Logical value. If TRUE, the sequence of colour values will be randomly permuted.

monochrome

Logical value. If TRUE, the colours will be converted to greyscale colours.

...

Additional arguments passed to methods.

Details

In the spatstat package, an object of class "colourmap" defines a mapping between data and colours.

The function default.colourmap provides a suitable default colour map for the values in x.

If x is a factor, default.colourmap(x) is a mapping from the factor levels to colours. If x is a logical vector, default.colourmap(x) is a mapping from the values TRUE and FALSE to colours. If x is a numeric vector, default.colourmap(x) is a mapping from numbers in the interval between the minimum and maximum values of x to colours.

The argument col may provide colour information in any of the following formats:

  • A colour map (object of class "colourmap")

  • A palette function (a function(n) or function(n, ...) which returns a vector of colour values, such as rainbow

  • A vector of integers between 1 and 8 indexing the standard colour palette

  • A vector of character strings giving common names of colours (e.g. "red")

  • A vector of character strings giving hexadecimal codes for colours (e.g. produced by rgb or rainbow)

  • NULL.

Value

A colour map (object of class "colourmap").

Scrambling the colours

The argument scramble.cols=TRUE will cause the sequence of colours in the colour map to be randomly permuted. This is a useful trick when it is desired that adjacent colours in the sequence should be easily distinguishable. The return value will be the randomised colour map.

Randomisation implies that the colour map will be different each time the command is executed. For reproducible results, set the random generator seed using set.seed.

Author(s)

\adrian

See Also

colourmap

Examples

  default.colourmap(letters[1:4])
  default.colourmap(factor(letters[1:3], levels=letters[1:4]))
  default.colourmap(TRUE)
  default.colourmap(NULL)

spatstat.geom documentation built on Jan. 20, 2026, 5:08 p.m.