knitr::opts_chunk$set( collapse = TRUE, comment = "#>", message = FALSE, warning = FALSE, fig.width = 6, fig.asp = 0.6, out.width = "70%", dpi = 300 )
This article will demonstrate each wrapper function.
library(dplyr) library(ggplot2) library(scales) library(ggblanket) library(palmerpenguins) set_blanket() penguins2 <- penguins |> labelled::set_variable_labels( bill_length_mm = "Bill length (mm)", bill_depth_mm = "Bill depth (mm)", flipper_length_mm = "Flipper length (mm)", body_mass_g = "Body mass (g)", ) |> mutate(sex = factor(sex, labels = c("Female", "Male"))) |> tidyr::drop_na(sex) experiment <- 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)) |> labelled::set_variable_labels( trt = "Treatment", resp = "Response" )
economics |> gg_area( x = date, y = unemploy, y_label = "Unemployment", )
penguins2 |> gg_bar( position = position_dodge(preserve = "single"), y = species, col = sex, width = 0.75, )
diamonds |> gg_bin_2d( x = carat, y = price, )
penguins2 |> gg_boxplot( x = flipper_length_mm, y = sex, col = species, blend = "multiply", )
penguins2 |> group_by(sex, species) |> summarise(across(flipper_length_mm, \(x) mean(x, na.rm = TRUE))) |> labelled::copy_labels_from(penguins2) |> gg_col( position = position_dodge(preserve = "single"), x = flipper_length_mm, y = species, col = sex, width = 0.75, )
faithfuld |> gg_contour( x = waiting, y = eruptions, z = density, )
faithfuld |> gg_contour_filled( x = waiting, y = eruptions, z = density, bins = 8, )
experiment |> gg_crossbar( x = trt, y = resp, ymin = lower, ymax = upper, col = group, width = 0.5, y_expand_limits = 0, blend = "multiply", )
penguins2 |> gg_density( x = flipper_length_mm, col = species, blend = "multiply", )
faithful |> gg_density_2d( x = waiting, y = eruptions, bins = 8, contour = TRUE, )
faithful |> gg_density_2d_filled( x = waiting, y = eruptions, bins = 8, contour = TRUE, )
experiment |> gg_errorbar( x = trt, ymin = lower, ymax = upper, col = group, y_label = "Response", width = 0.1, y_expand_limits = 0, )
penguins2 |> gg_freqpoly( x = flipper_length_mm, col = sex, mode = light_mode_t(), ) + theme(legend.title = element_blank())
gg_function( fun = \(x) dnorm(x, mean = 0, sd = 5), x_expand_limits = qnorm(p = c(0.005, 0.995), mean = 0, sd = 5), x_label = "X", y_expand_limits = 0, )
diamonds |> gg_hex( x = carat, y = price, )
penguins2 |> gg_histogram( x = flipper_length_mm, col = sex, facet = species, bins = 50, mode = light_mode_t(), ) + theme(legend.title = element_blank())
set.seed(123) penguins2 |> gg_jitter( position = position_jitter(), x = species, y = body_mass_g, col = flipper_length_mm, y_expand_limits = 0, col_steps = TRUE, )
bind_rows( mtcars |> slice_min(order_by = mpg), mtcars |> slice_max(order_by = mpg)) |> tibble::rownames_to_column("model") |> gg_label( x = model, y = mpg, label = model, y_expand_limits = 0, y_label = "Miles per gallon", )
economics |> gg_line( x = date, y = unemploy, y_expand_limits = 0, y_label = "Unemployment", )
experiment |> gg_linerange( position = position_dodge(width = 0.2), x = trt, ymin = lower, ymax = upper, col = group, y_label = "Response", y_expand_limits = 0, )
economics |> mutate(unemploy_rate = unemploy / pop) |> gg_path( x = unemploy_rate, y = psavert, x_label = "Unemployment rate", y_expand_limits = 0, y_label = "Personal savings rate", )
penguins2 |> gg_point( x = flipper_length_mm, y = body_mass_g, col = species, )
experiment |> gg_pointrange( position = position_dodge(width = 0.2), x = trt, y = resp, col = group, ymin = lower, ymax = upper, y_expand_limits = 0, )
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, )
penguins2 |> gg_qq( sample = body_mass_g, facet = species, coord = coord_cartesian(clip = "on"), ) + geom_qq_line()
penguins2 |> gg_quantile( x = flipper_length_mm, y = body_mass_g, )
faithfuld |> gg_raster( x = waiting, y = eruptions, col = density, )
data.frame( x = rep(c(2, 5, 7, 9, 12), 2), y = rep(c(1, 2), each = 5), z = factor(c(rep(1:4, each = 2), 5, NA)), w = rep(diff(c(0, 4, 6, 8, 10, 14)), 2)) |> mutate( xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1 ) |> gg_rect( xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax, col = z, )
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, x_labels = \(x) x, y_label = "Level", )
data.frame(year = 1875:1972, level = as.vector(LakeHuron)) |> mutate(level_min = level - 1, level_max = level + 1) |> gg_ribbon_line( x = year, y = level, ymin = level_min, ymax = level_max, x_labels = \(x) x, blend = "multiply", )
penguins2 |> gg_rug( x = flipper_length_mm, y = body_mass_g, col = sex, )
data.frame(x1 = 2.62, x2 = 3.57, y1 = 21.0, y2 = 15.0) |> gg_segment( x = x1, xend = x2, y = y1, yend = y2, )
sf::st_read(system.file("shape/nc.shp", package = "sf")) |> gg_sf( col = AREA, )
penguins2 |> gg_smooth( x = flipper_length_mm, y = body_mass_g, col = sex, blend = "multiply", se = TRUE, )
economics |> filter(date > lubridate::ymd("2010-01-01")) |> gg_step( x = date, y = unemploy, y_expand_limits = 0, y_label = "Unemployment", )
bind_rows( mtcars |> slice_min(order_by = mpg), mtcars |> slice_max(order_by = mpg)) |> tibble::rownames_to_column("model") |> gg_text( x = model, y = mpg, label = model, y_expand_limits = 0, y_label = "Miles per gallon", )
penguins2 |> group_by(species, sex) |> summarise(flipper_length_mm = mean(flipper_length_mm, na.rm = TRUE)) |> labelled::copy_labels_from(penguins2) |> gg_tile( x = sex, y = species, col = flipper_length_mm, )
penguins2 |> gg_violin( x = sex, y = body_mass_g, col = species, )
penguins2 |> gg_blanket( geom = "violin", stat = "ydensity", position = "dodge", x = sex, y = body_mass_g, col = species, )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.