Learn R Programming

ggblanket (version 1.4.0)

gg_sf: Sf ggplot.

Description

Create a sf plot with a wrapper around the ggplot2:: %>% function.

Usage

gg_sf(
  data = NULL,
  col = NULL,
  facet = NULL,
  facet2 = NULL,
  group = NULL,
  text = NULL,
  stat = "sf",
  position = "identity",
  pal = NULL,
  pal_na = "#7F7F7F",
  alpha = 0.9,
  ...,
  titles = NULL,
  title = NULL,
  subtitle = NULL,
  coord = ggplot2::coord_sf(),
  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_title = NULL,
  facet_labels = NULL,
  facet_ncol = NULL,
  facet_nrow = NULL,
  facet_layout = NULL,
  caption = NULL,
  theme = NULL
)

Value

A ggplot object.

Arguments

data

A sf object.

col

Unquoted col and fill aesthetic variable.

facet

Unquoted facet aesthetic variable.

facet2

Unquoted second facet variable.

group

Unquoted group aesthetic variable.

text

Unquoted text aesthetic variable, which can be used in combination with plotly::ggplotly(., tooltip = "text").

stat

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

position

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

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).

alpha

Opacity. A number between 0 and 1.

...

Other arguments passed to the relevant ggplot2::geom_* function.

titles

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

title

Title string.

subtitle

Subtitle string.

coord

Coordinate system.

col_breaks

A function that takes the limits as input (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".

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. "b" for bottom, "r" for right, "t" for top, or "l" for left. Defaults to "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 axis.

col_title

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

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_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.

theme

A ggplot2 theme.

Examples

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

  gg_sf(nc, col = AREA, col_legend_place = "b")
}

Run the code above in your browser using DataLab