Learn R Programming

diceplot (version 0.2.0)

geom_dice_sf: Plot Dice Representations on sf Objects

Description

Creates a ggplot2 layer that places dice representations on spatial features in an sf object. The dice values are determined by a column in the sf object.

Creates a ggplot2 layer that places dice representations on spatial features in an sf object. The dice values are determined by a column in the sf object.

Usage

geom_dice_sf(
  sf_data,
  dice_value_col = "dice",
  face_color = NULL,
  dice_color = "white",
  dice_size = 3,
  dot_size = NULL,
  rectangle_padding = 0.05,
  ...
)

geom_dice_sf( sf_data, dice_value_col = "dice", face_color = NULL, dice_color = "white", dice_size = 3, dot_size = NULL, rectangle_padding = 0.05, ... )

Value

A list of ggplot2 layers (rectangle layer and dots layer).

A list of ggplot2 layers (rectangle layer and dots layer).

Arguments

sf_data

An sf object containing the spatial features.

dice_value_col

Character. Name of the column in sf_data containing dice values (1-6). Default is "dice".

face_color

Character vector. Column names in sf_data containing color information for each dice dot. If NULL (default), all dots are black.

dice_color

Character. Background color of the dice. Default is "white".

dice_size

Numeric. Size of the dice. Default is 3.

dot_size

Numeric. Size of the dots on the dice. If NULL (default), it's calculated as 20% of dice_size.

rectangle_padding

Numeric. Padding of the rectangle around the dots, as a proportion of dice_size. Default is 0.05.

...

Additional arguments passed to geom_point for the dots.

Examples

Run this code
if (FALSE) {
library(ggplot2)
library(sf)

# Create sample sf data with dice values
nc <- st_read(system.file("shape/nc.shp", package = "sf"))
nc$dice <- sample(1:6, nrow(nc), replace = TRUE)

# Basic plot with dice
ggplot(nc) + 
  geom_sf() + 
  geom_dice_sf(sf_data = nc)
  
# Customized dice
ggplot(nc) + 
  geom_sf() + 
  geom_dice_sf(sf_data = nc, dice_color = "lightblue", dice_size = 5)
}

if (FALSE) {
library(ggplot2)
library(sf)

# Create sample sf data with dice values
nc <- st_read(system.file("shape/nc.shp", package = "sf"))
nc$dice <- sample(1:6, nrow(nc), replace = TRUE)

# Basic plot with dice
ggplot(nc) + 
  geom_sf() + 
  geom_dice_sf(sf_data = nc)
  
# Customized dice
ggplot(nc) + 
  geom_sf() + 
  geom_dice_sf(sf_data = nc, dice_color = "lightblue", dice_size = 5)
}

Run the code above in your browser using DataLab