Skip to contents

Plots a surprise map using sf's plot method. For ggplot2 integration, see geom_surprise() and scale_fill_surprise().

Usage

# S3 method for class 'bs_surprise_sf'
plot(
  x,
  y = NULL,
  which = c("surprise", "signed_surprise"),
  pal = NULL,
  breaks = NULL,
  nbreaks = 9,
  main = NULL,
  border = "grey50",
  lwd = 0.2,
  key.pos = 4,
  ...
)

Arguments

x

A bs_surprise_sf object

y

Unused (for S3 method compatibility)

which

Which variable to plot: "surprise" or "signed_surprise"

pal

Color palette. If NULL, uses default diverging palette for signed surprise and sequential for unsigned.

breaks

Breaks for color scale. If NULL, uses pretty breaks.

nbreaks

Number of breaks if breaks is NULL

main

Plot title. If NULL, auto-generated.

border

Border color for polygons

lwd

Line width for borders

key.pos

Position of legend (1=below, 2=left, 3=above, 4=right, NULL=none)

...

Additional arguments passed to sf::plot()

Value

Invisibly returns the input object

Examples

library(sf)
nc <- st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
result <- surprise(nc, observed = SID74, expected = BIR74)

# Default plot
plot(result)


# Plot signed surprise
plot(result, which = "signed_surprise")


# Custom palette
plot(result, pal = heat.colors(9))