Learn R Programming

ggblanket (version 2.0.0)

gg_sf: Sf ggplot

Description

Create a blank ggplot with a wrapper around the ggplot2::geom_sf function.

Usage

gg_sf(
  data = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  position = "identity",
  stat = "sf",
  coord = ggplot2::coord_sf(clip = "off"),
  pal = NULL,
  pal_na = pal_grey,
  ...,
  title = NULL,
  subtitle = NULL,
  x_grid = FALSE,
  x_title = NULL,
  y_grid = FALSE,
  y_title = NULL,
  col_breaks = NULL,
  col_continuous = "gradient",
  col_include = NULL,
  col_labels = NULL,
  col_legend_place = NULL,
  col_legend_ncol = NULL,
  col_legend_nrow = NULL,
  col_legend_rev = FALSE,
  col_limits = NULL,
  col_oob = scales::oob_censor,
  col_rescale = NULL,
  col_title = NULL,
  col_trans = "identity",
  facet_labels = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_scales = "fixed",
  facet_space = "fixed",
  facet_layout = NULL,
  caption = NULL,
  titles = snakecase::to_sentence_case,
  theme = gg_theme(),
  void = TRUE
)

Value

A ggplot object.

Arguments

data

A data frame or tibble.

col

Unquoted col and fill aesthetic variable.

facet

Unquoted facet aesthetic variable.

facet2

Unquoted second facet variable.

group

Unquoted group aesthetic variable.

position

Position adjustment. Either a character string (e.g."identity"), or a function (e.g. ggplot2::position_identity()).

stat

Statistical transformation. A character string (e.g. "identity").

coord

A coordinate function from ggplot2 (e.g. ggplot2::coord_cartesian()).

pal

Colours to use. A character vector of hex codes (or names).

pal_na

Colour to use for NA values. A character vector of a hex code (or name).

...

Other arguments passed to the ggplot2::geom_sf function.

title

Title string.

subtitle

Subtitle string.

x_grid

TRUE or FALSE for vertical x gridlines. NULL guesses based on the classes of the x and y.

x_title

Axis title string. Defaults to converting to sentence case with spaces. Use "" for no title.

y_grid

TRUE or FALSE of horizontal y gridlines. NULL guesses based on the classes of the x and y.

y_title

Axis title string. Defaults to converting to sentence case with spaces. Use "" for no title.

col_breaks

A function on the limits (e.g. scales::breaks_pretty()), or a vector of breaks.

col_continuous

Type of colouring for a continuous variable. Either "gradient" or "steps". Defaults to "steps" - or just the first letter of these e.g. "g".

col_include

For a numeric or date variable, any values that the scale should include (e.g. 0).

col_labels

A function that takes the breaks as inputs (e.g. scales::label_comma()), or a vector of labels. Note this does not affect where col_intervals is not NULL.

col_legend_place

The place for the legend. Either "bottom", "right", "top" or "left" - or just the first letter of these e.g. "b".

col_legend_ncol

The number of columns for the legend elements.

col_legend_nrow

The number of rows for the legend elements.

col_legend_rev

Reverse the elements of the legend. Defaults to FALSE.

col_limits

A vector to determine the limits of the colour scale.

col_oob

A scales::oob_* function that handles values outside of limits for continuous scales. Defaults to scales::oob_censor.

col_rescale

For a continuous col variable, a vector to rescale the pal non-linearly.

col_title

Legend title string. Defaults to converting to sentence case with spaces. Use "" for no title.

col_trans

For a numeric variable, a transformation object (e.g. "log10", "sqrt" or "reverse").

facet_labels

A function that takes the breaks as inputs (e.g. scales::label_comma()), or a named vector of labels (e.g. c("value" = "label", ...)).

facet_ncol

The number of columns of facets. Only applies to a facet layout of "wrap".

facet_nrow

The number of rows of facets. Only applies to a facet layout of "wrap".

facet_scales

Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".

facet_space

Whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed". Only applies where the facet layout is "grid" and facet scales are not "fixed".

facet_layout

Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".

caption

Caption title string.

titles

A function to format the x, y and col titles. Defaults to snakecase::to_sentence_case.

theme

A ggplot2 theme.

void

TRUE or FALSE of whether to remove axis lines, ticks and x and y titles and labels.

Examples

Run this code
if (requireNamespace("sf", quietly = TRUE)) {
  nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)

  nc |>
    gg_sf(
      col = AREA,
      pal = viridis::cividis(9))
}

Run the code above in your browser using DataLab