protomapr/man/pmPalette.Rd
2026-03-06 15:46:39 +11:00

61 lines
1.8 KiB
R

% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/palette.R
\name{pmPalette}
\alias{pmPalette}
\title{Apply Color Palette to Land Use Categories}
\usage{
pmPalette(palette, categories = NULL, n = NULL, background = "#f8f8f8")
}
\arguments{
\item{palette}{Character vector of colors, or a function that generates colors.
Can be output from viridis::viridis(), RColorBrewer::brewer.pal(), etc.}
\item{categories}{Character vector of category names to map colors to.
Default maps to common land use types: water, park, wood, residential,
commercial, industrial.}
\item{n}{Integer. Number of colors to generate if palette is a function.
Default is NULL (uses length of categories).}
\item{background}{Character. Background/default color for unassigned categories.
Default is "#f8f8f8".}
}
\value{
A list of color mappings suitable for pmColors() or addProtomaps(colors=).
}
\description{
Maps colors from a palette to land use categories, enabling use of
viridis, RColorBrewer, and other R color palettes with Protomaps.
}
\examples{
\dontrun{
library(leaflet)
library(protomapr)
# Using viridis palette for land use
if (requireNamespace("viridisLite", quietly = TRUE)) {
colors <- pmPalette(viridisLite::viridis(6))
leaflet() \%>\%
setView(lng = -122.4, lat = 37.8, zoom = 12) \%>\%
addProtomaps(url = protomaps_url(), colors = colors)
}
# Using RColorBrewer
if (requireNamespace("RColorBrewer", quietly = TRUE)) {
colors <- pmPalette(RColorBrewer::brewer.pal(6, "Set2"))
leaflet() \%>\%
setView(lng = -122.4, lat = 37.8, zoom = 12) \%>\%
addProtomaps(url = protomaps_url(), colors = colors)
}
# Custom category mapping
colors <- pmPalette(
c("#264653", "#2a9d8f", "#e9c46a", "#f4a261", "#e76f51"),
categories = c("water", "park", "sand", "buildings", "highway")
)
}
}
\seealso{
\code{\link{pmPaletteStyle}}, \code{\link{pmColors}}
}