Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

findColours

assign colours to classes from classInterval object


Description

This helper function is a wrapper for findCols to extract classes from a "classInterval" object and assign colours from a palette created by colorRampPalette from the two or more colours given in the pal argument. It also returns two attributes for use in constructing a legend.

Usage

findColours(clI, pal, under="under", over="over", between="-", 
 digits = getOption("digits"), cutlabels=TRUE)

Arguments

clI

a "classIntervals" object

pal

a character vector of at least two colour names; colorRampPalette is used internally to create the required number of colours

under

character string value for "under" in legend if cutlabels=FALSE

over

character string value for "over" in legend if cutlabels=FALSE

between

character string value for "between" in legend if cutlabels=FALSE

digits

minimal number of significant digits in legend

cutlabels

use cut-style labels in legend

Value

a character vector of colours with attributes: "table", a named frequency table; "palette", a character vector of colours corresponding to the specified breaks.

Author(s)

Roger Bivand <Roger.Bivand@nhh.no

See Also

Examples

if (!require("spData", quietly=TRUE)) {
  message("spData package needed for examples")
  run <- FALSE
} else {
  run <- TRUE
}
if (run) {
data(jenks71, package="spData")
mypal <- c("wheat1", "red3")
h5 <- classIntervals(jenks71$jenks71, n=5, style="hclust", method="complete")
print(findColours(h5, mypal))
}
if (run) {
print(findColours(getHclustClassIntervals(h5, k=7), mypal))
}
if (run) {
h5Colours <- findColours(h5, mypal)
plot(h5, mypal, main="Complete hierarchical clustering")
legend(c(95, 155), c(0.12, 0.4), fill=attr(h5Colours, "palette"),
 legend=names(attr(h5Colours, "table")), bg="white")
}
if (run) {
h5tab <- attr(h5Colours, "table")
legtext <- paste(names(h5tab), " (", h5tab, ")", sep="")
plot(h5, mypal, main="Complete hierarchical clustering (with counts)")
legend(c(95, 165), c(0.12, 0.4), fill=attr(h5Colours, "palette"),
 legend=legtext, bg="white")
}

classInt

Choose Univariate Class Intervals

v0.4-3
GPL (>= 2)
Authors
Roger Bivand [aut, cre] (<https://orcid.org/0000-0003-2392-6140>), Hisaji Ono [ctb], Richard Dunlap [ctb], Matthieu Stigler [ctb], Bill Denney [ctb] (<https://orcid.org/0000-0002-5759-428X>), Diego Hernangómez [ctb] (<https://orcid.org/0000-0001-8457-4658>)
Initial release
2020-04-05

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.