Functions demo (dark_mode)
David Hodge
Source:vignettes/articles/2_functions_demo_dark-Rmd.Rmd
2_functions_demo_dark-Rmd.Rmd
Overview
This article will demonstrate each wrapper function.
library(ggblanket)
library(ggplot2)
library(dplyr)
library(stringr)
library(tidyr)
library(palmerpenguins)
theme_set(dark_mode_rt())
gg_area
economics |>
gg_area(
x = date,
y = unemploy,
y_title = "Unemployment",
)
gg_bar
penguins |>
mutate(across(sex, \(x) str_to_sentence(x))) |>
gg_bar(
y = species,
col = sex,
position = position_dodge(preserve = "single"),
width = 0.75,
)
gg_boxplot
penguins |>
drop_na(sex) |>
mutate(across(sex, \(x) str_to_sentence(x))) |>
gg_boxplot(
x = flipper_length_mm,
y = sex,
col = species,
theme = dark_mode_b(),
)
gg_col
penguins |>
drop_na(sex) |>
mutate(across(sex, \(x) str_to_sentence(x))) |>
group_by(sex, species) |>
summarise(across(flipper_length_mm, \(x) mean(x, na.rm = TRUE))) |>
gg_col(
x = flipper_length_mm,
y = species,
col = sex,
position = position_dodge(preserve = "single"),
width = 0.75,
)
gg_contour
faithfuld |>
gg_contour(
x = waiting,
y = eruptions,
z = density,
)
gg_contour_filled
faithfuld |>
gg_contour_filled(
x = waiting,
y = eruptions,
z = density,
bins = 8,
)
gg_crossbar
data.frame(
trt = factor(c(1, 1, 2, 2)),
resp = c(1, 5, 3, 4),
group = factor(c(1, 2, 1, 2)),
upper = c(1.1, 5.3, 3.3, 4.2),
lower = c(0.8, 4.6, 2.4, 3.6)) |>
gg_crossbar(
x = trt,
y = resp,
ymin = lower,
ymax = upper,
col = group,
width = 0.5,
x_title = "Treatment",
y_title = "Response",
)
gg_density
penguins |>
drop_na(sex) |>
mutate(across(sex, \(x) str_to_sentence(x))) |>
gg_density(
x = flipper_length_mm,
col = species,
theme = dark_mode_t(),
)
gg_density_2d
faithful |>
gg_density_2d(
x = waiting,
y = eruptions,
bins = 8,
)
gg_density_2d_filled
faithful |>
gg_density_2d_filled(
x = waiting,
y = eruptions,
bins = 8,
col_pal = viridisLite::mako(8),
)
gg_errorbar
data.frame(
trt = factor(c(1, 1, 2, 2)),
resp = c(1, 5, 3, 4),
group = factor(c(1, 2, 1, 2)),
upper = c(1.1, 5.3, 3.3, 4.2),
lower = c(0.8, 4.6, 2.4, 3.6)
) |>
gg_errorbar(
x = trt,
ymin = lower,
ymax = upper,
col = group,
width = 0.1,
x_title = "Treatment",
y_title = "Response",
)
gg_freqpoly
penguins |>
mutate(across(sex, \(x) str_to_sentence(x))) |>
gg_freqpoly(
x = flipper_length_mm,
col = sex,
col_title = "",
theme = dark_mode_t(),
)
gg_hex
diamonds |>
gg_hex(
x = carat,
y = price,
y_limits = c(0, 20000),
coord = coord_cartesian(clip = "on"),
col_pal = viridisLite::mako(9),
)
gg_histogram
penguins |>
mutate(across(sex, \(x) str_to_sentence(x))) |>
gg_histogram(
x = flipper_length_mm,
col = sex,
facet = species,
bins = 50,
theme = dark_mode_b(),
)
gg_jitter
set.seed(123)
penguins |>
gg_jitter(
x = species,
y = body_mass_g,
col = flipper_length_mm,
position = position_jitter(height = 0),
y_expand_limits = 0,
col_continuous = "steps",
col_labels = \(x) replace_seq(x),
col_pal = viridisLite::mako(9),
)
gg_line
economics |>
gg_line(
x = date,
y = unemploy,
y_expand_limits = 0,
y_title = "Unemployment",
)
gg_linerange
data.frame(
trt = factor(c(1, 1, 2, 2)),
resp = c(1, 5, 3, 4),
group = factor(c(1, 2, 1, 2)),
upper = c(1.1, 5.3, 3.3, 4.2),
lower = c(0.8, 4.6, 2.4, 3.6)) |>
gg_linerange(
x = trt,
ymin = lower,
ymax = upper,
col = group,
position = position_dodge(width = 0.2),
x_title = "Treatment",
y_title = "Response",
)
gg_point
penguins |>
mutate(across(sex, \(x) str_to_sentence(x))) |>
gg_point(
x = flipper_length_mm,
y = body_mass_g,
col = sex,
facet = species,
theme = dark_mode_b(),
)
gg_pointrange
data.frame(
trt = factor(c(1, 1, 2, 2)),
resp = c(1, 5, 3, 4),
group = factor(c(1, 2, 1, 2)),
upper = c(1.1, 5.3, 3.3, 4.2),
lower = c(0.8, 4.6, 2.4, 3.6)) |>
gg_pointrange(
x = trt,
y = resp,
col = group,
ymin = lower,
ymax = upper,
position = position_dodge(width = 0.2),
size = 0.2,
x_title = "Treatment",
y_title = "Response",
)
gg_polygon
ids <- factor(c("1.1", "2.1", "1.2", "2.2", "1.3", "2.3"))
values <- data.frame(
id = ids,
value = c(3, 3.1, 3.1, 3.2, 3.15, 3.5)
)
positions <- data.frame(
id = rep(ids, each = 4),
x = c(2, 1, 1.1, 2.2, 1, 0, 0.3, 1.1, 2.2, 1.1, 1.2, 2.5, 1.1, 0.3,
0.5, 1.2, 2.5, 1.2, 1.3, 2.7, 1.2, 0.5, 0.6, 1.3),
y = c(-0.5, 0, 1, 0.5, 0, 0.5, 1.5, 1, 0.5, 1, 2.1, 1.7, 1, 1.5,
2.2, 2.1, 1.7, 2.1, 3.2, 2.8, 2.1, 2.2, 3.3, 3.2)
)
datapoly <- merge(values, positions, by = c("id"))
datapoly |>
gg_polygon(
x = x,
y = y,
col = value,
group = id,
)
gg_qq
penguins |>
gg_qq(
sample = body_mass_g,
facet = species,
coord = coord_cartesian(clip = "on"),
) +
geom_qq_line(
colour = pal_blue,
)
gg_ribbon
data.frame(year = 1875:1972, level = as.vector(LakeHuron)) |>
mutate(level_min = level - 1, level_max = level + 1) |>
gg_ribbon(
x = year,
ymin = level_min,
ymax = level_max,
y_title = "Level",
col_pal = scales::alpha(pal_blue, 0),
) +
geom_line(
mapping = aes(x = year, y = level),
colour = pal_blue,
)
gg_segment
data.frame(x1 = 2.62, x2 = 3.57, y1 = 21.0, y2 = 15.0) |>
gg_segment(
x = x1,
xend = x2,
y = y1,
yend = y2,
)
gg_sf
sf::st_read(system.file("shape/nc.shp", package = "sf")) |>
gg_sf(
col = AREA,
col_pal = viridisLite::mako(9),
)
#> Reading layer `nc' from data source
#> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile'
#> Simple feature collection with 100 features and 14 fields
#> Geometry type: MULTIPOLYGON
#> Dimension: XY
#> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> Geodetic CRS: NAD27
gg_smooth
penguins |>
drop_na(sex) |>
mutate(across(sex, \(x) str_to_sentence(x))) |>
gg_smooth(
x = flipper_length_mm,
y = body_mass_g,
col = sex,
se = TRUE,
)
gg_step
economics |>
gg_step(
x = date,
y = unemploy,
coord = coord_cartesian(clip = "on"),
x_limits = c(lubridate::ymd("2010-01-01"), lubridate::NA_Date_),
y_expand_limits = 0,
y_title = "Unemployment",
)
gg_violin
penguins |>
drop_na(sex) |>
mutate(across(sex, \(x) str_to_sentence(x))) |>
gg_violin(
x = sex,
y = body_mass_g,
col = sex,
facet = species,
theme = dark_mode_b(),
)
ggblanket
penguins |>
drop_na(sex) |>
mutate(across(sex, \(x) str_to_sentence(x))) |>
gg_blanket(
geom = "violin",
stat = "ydensity",
position = "dodge",
x = sex,
y = body_mass_g,
col = sex,
facet = species,
theme = dark_mode_b(),
)