| Title: | Extend 'ggplot2' with Layers and Scales for Spatial Uncertainty Visualization |
| Version: | 0.1.0 |
| Description: | Provide specialized 'ggplot2' layers and scales for spatial uncertainty visualization, including bivariate choropleth maps, pixel maps, glyph maps, and exceedance probability maps. |
| Imports: | dplyr, grDevices, grid, gtable, rlang, scales, sf, stats, withr |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.2 |
| Suggests: | testthat (≥ 3.0.0), vdiffr |
| Config/testthat/edition: | 3 |
| Depends: | ggplot2 (≥ 3.5.0), R (≥ 4.1.0) |
| LazyData: | true |
| URL: | https://github.com/maggiexma/ggincerta |
| BugReports: | https://github.com/maggiexma/ggincerta/issues |
| NeedsCompilation: | no |
| Packaged: | 2025-11-07 13:13:56 UTC; maxueqi |
| Author: | Xueqi Ma [aut, cre, cph],
Emi Tanaka |
| Maintainer: | Xueqi Ma <maggiexma07@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2025-11-11 22:00:02 UTC |
ggincerta: Extend 'ggplot2' with Layers and Scales for Spatial Uncertainty Visualization
Description
Provide specialized 'ggplot2' layers and scales for spatial uncertainty visualization, including bivariate choropleth maps, pixel maps, glyph maps, and exceedance probability maps.
Author(s)
Maintainer: Xueqi Ma maggiexma07@gmail.com [copyright holder]
Authors:
Emi Tanaka dr.emi.tanaka@gmail.com (ORCID) [thesis advisor]
Other contributors:
Weihao Li [thesis advisor]
Quan Vu [thesis advisor]
Francis Hui [thesis advisor]
See Also
Useful links:
Bivariate color scales
Description
scale_*_bivariate creates a bivariate palette by mixing two colour ramps,
then implements the mapping by binning the variables v1, v2 and assigning
each bin combination to a colour.
Usage
ScaleBivariate
scale_fill_bivariate(
name1 = NULL,
name2 = NULL,
colors = c("gold", "red4"),
n_breaks = 4,
breaks = c("quantile", "equal"),
flip = c("none", "vertical", "horizontal", "both"),
guide_size = 1.5,
na.value = NA,
na.translate = TRUE,
aesthetics = "fill",
...
)
scale_color_bivariate(
name1 = NULL,
name2 = NULL,
colors = c("gold", "red4"),
n_breaks = 4,
breaks = c("quantile", "equal"),
flip = c("none", "vertical", "horizontal", "both"),
guide_size = 1.5,
na.value = NA,
na.translate = TRUE,
aesthetics = "colour",
...
)
scale_colour_bivariate(
name1 = NULL,
name2 = NULL,
colors = c("gold", "red4"),
n_breaks = 4,
breaks = c("quantile", "equal"),
flip = c("none", "vertical", "horizontal", "both"),
guide_size = 1.5,
na.value = NA,
na.translate = TRUE,
aesthetics = "colour",
...
)
Arguments
name1, name2 |
Optional names for |
colors |
A character vector of length two specifying the colors for the bivariate palette. |
n_breaks |
An integer guiding the number of bins for each variable. |
breaks |
Method used to bin the variables: |
flip |
Method used to flip the legend: |
guide_size |
A numeric value controlling the size of the legend graphic, in centimeters. |
na.value |
If |
na.translate |
Unlike continuous scales, discrete scales can easily show
missing values, and do so by default. If you want to remove missing values
from a discrete scale, specify |
aesthetics |
The names of the aesthetics that this scale works with. |
... |
Other arguments passed to |
Format
An object of class ScaleBivariate (inherits from ScaleDiscrete, Scale, ggproto, gg) of length 5.
Value
A ScaleBivariate ggproto object.
See Also
ggplot2::Scale for the base ggproto class that all scale objects
inherit from.
Examples
# Create a bivariate fill scale
sc <- scale_fill_bivariate()
class(sc)
sc$palette(9)
# Basic bivariate map
p <- ggplot(nc) + geom_sf(aes(fill = duo(value, sd)))
# Customize axis labels
p + scale_fill_bivariate(name1 = 'var1', name2 = 'var2')
Exceedance probability colour scales
Description
scale_*_exceed computes exceedance probabilities from a specified
distribution and maps onto a continuous gradient colour scale.
Usage
ScaleExceed
scale_fill_exceed(
name = NULL,
palette = "Oranges",
type = "seq",
direction = 1,
dist_fun = NULL,
threshold = 1.64,
limits = c(0, 1),
na.value = NA,
guide = "colourbar",
aesthetics = "fill",
...
)
scale_colour_exceed(
name = NULL,
palette = "Oranges",
type = "seq",
direction = 1,
dist_fun = NULL,
threshold = 1.64,
limits = c(0, 1),
na.value = NA,
guide = "colourbar",
aesthetics = "colour",
...
)
Arguments
name |
The name of the scale. Used as the axis or legend title. If
|
palette |
A palette function that when called with a numeric vector with
values between 0 and 1 returns the corresponding output values
(e.g., |
type |
One of "seq" (sequential), "div" (diverging) or "qual" (qualitative) |
direction |
Sets the order of colours in the scale. If 1, the default,
colours are as output by |
dist_fun |
A function used to compute the exceedance probability.
If |
threshold |
A numeric value specifying the threshold |
limits |
One of:
|
na.value |
Missing values will be replaced with this value. |
guide |
A function used to create a guide or its name. See
|
aesthetics |
The names of the aesthetics that this scale works with. |
... |
Other arguments passed to |
Format
An object of class ScaleExceed (inherits from ScaleContinuous, Scale, ggproto, gg) of length 2.
Value
A ScaleExceed ggproto object.
Examples
# Create an exceedance probability scale
sc <- scale_fill_exceed()
class(sc)
# Basic bivariate map
p <- ggplot(nc) + geom_sf(aes(fill = duo_exceed(value, sd)))
Generate glyph maps on sf objects
Description
geom_sf_glyph() adds a glyph map layer based on simple feature (sf) objects
to a ggplot. A glyph map is essentially a centroid-based map, where each
region is represented by a rotated glyph, and the rotation angle indicates
the value of v2 specified in the mapping.
Usage
StatGlyph
geom_sf_glyph(
mapping = NULL,
data = NULL,
size = 70,
style = "icone",
max_v2 = NULL,
position = "identity",
show.legend = TRUE,
inherit.aes = TRUE,
...
)
Arguments
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
size |
A positive numeric scaling factor controlling glyph size. Larger values produce smaller glyphs. |
style |
Either |
max_v2 |
Numeric value setting the upper limit for |
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
show.legend |
logical. Should this layer be included in the legends?
You can also set this to one of "polygon", "line", and "point" to override the default legend. |
inherit.aes |
If |
... |
Other arguments passed on to
|
Format
An object of class StatGlyph (inherits from StatSf, Stat, ggproto, gg) of length 3.
Value
A list of ggplot2 layer objects.
Glyph map layer contents
The layer returned by geom_sf_glyph() actually contains two scales,
corresponding to the two variables specified in the mapping.
Therefore, modifying the scale for v1 will trigger a warning
indicating that the scale for fill is being replaced.
Examples
# Basic glyph map
p <- ggplot(nc) + geom_sf_glyph(mapping = aes(v1 = value, v2 = sd))
p1 <- ggplot(nc) + geom_sf_glyph(mapping = aes(v1 = value, v2 = sd), style = "semi")
# Customize labels and theme
p + labs(title = "glyph map on nc") + theme(legend.position = "left", legend.box = "horizontal")
# Replacing the internal fill scale triggers a message
# ("Scale for fill is already present. Adding another scale for fill...")
p + scale_fill_distiller(palette = "Blues")
Generate pixel maps on sf objects
Description
geom_sf_pixel() adds a pixel map layer based on simple feature (sf) objects
to a ggplot. In a pixel map, each region is divided into small pixels, with
colours mapped from values sampled from distribution specified.
Usage
StatPixel
geom_sf_pixel(
mapping = NULL,
data = NULL,
n = 40,
distribution = "uniform",
seed = NULL,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
...
)
Arguments
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
n |
integer of length 1 or 2, number of grid cells in x and y direction (columns, rows) |
distribution |
Sampling distribution:
|
seed |
Random seed used to ensure reproducibility of the sampling process. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
You can also set this to one of "polygon", "line", and "point" to override the default legend. |
inherit.aes |
If |
... |
Other arguments passed on to
|
Format
An object of class StatPixel (inherits from StatSf, Stat, ggproto, gg) of length 3.
Value
A list of ggplot2 layer objects.
Pixel map layer contents
The layer returned by geom_sf_pixel() internally includes a scale object
created by scale_fill_distiller().
Therefore, modifying the scale will trigger a message indicating that
the scale for fill is being replaced.
Examples
# Basic pixel map
p <- ggplot(nc) + geom_sf_pixel(mapping = aes(v1 = value, v2 = sd), n = 20)
# Replacing the internal fill scale triggers a message
# ("Scale for fill is already present. Adding another scale for fill...")
p + scale_fill_distiller(palette = "Blues")
Format input and assign the "map" class
Description
duo() and duo_exceed() create paired mapping objects that combine two
variables, record their names, and assign the bivariate/exceed class as
an attribute for use in aesthetic mappings.
Usage
duo(v1, v2)
duo_exceed(estimate, error)
Arguments
v1, v2 |
Input variables for |
estimate, error |
Input variables for |
Value
A list-like object containing pairs of values from the two variables, with attributes storing the variable names and the class.
Examples
value <- nc$value
sd <- nc$sd
res <- duo(value, sd)
res_exceed <- duo_exceed(value, sd)
class(res); class(res_exceed)
attr(res, "vars"); attr(res_exceed, "vars")
North Carolina SIDS data
Description
The dataset nc is derived from the North Carolina shapefile (nc.shp)
included in the sf package. Two random variables, value and sd,
have been added for demonstration purposes.
Further details about the original data can be found in the spdep package vignette.
Usage
nc
Format
A sf object.
Examples
head(nc)
plot(sf::st_geometry(nc))