How it works

if (!("canvasXpress" %in% installed.packages())) {
    devtools::install_github('neuhausi/canvasXpress')
}
#devtools::install_local("~/git/canvas/R/canvasXpress.tar.gz", build_manual = TRUE, upgrade = "always")
library(ggblanket)
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.1
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(stringr)
library(tidyr)
library(palmerpenguins)
library(patchwork)
library(canvasXpress)

set_blanket()

Almost forty gg_* wrapper functions

p <- penguins |>
  gg_point(
    x = flipper_length_mm,
    y = body_mass_g,
  )
p
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_point()`).

canvasXpress(p, width = 672, height = 500)

A single col argument to colour and fill by a variable

p <- penguins |>
  gg_point(
    x = flipper_length_mm,
    y = body_mass_g, 
    col = species,
  )
p
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_point()`).

canvasXpress(p, width = 672, height = 500)
p <- penguins |>
  drop_na(sex) |>
  mutate(across(sex, str_to_sentence)) |>
  gg_bar(
    position = "dodge",
    y = species, 
    col = sex,
    width = 0.75,
  )
p

canvasXpress(p, width = 672, height = 500)

A facet argument to facet by a variable

p <- penguins |>
  drop_na(sex) |> 
  mutate(across(sex, str_to_sentence)) |> 
  gg_histogram(
    x = flipper_length_mm,
    facet = species,
    binwidth = 2
  )
p

canvasXpress(p, width = 672, height = 500)

A facet2 argument to facet by a 2nd variable

p <- penguins |>
  mutate(across(sex, str_to_sentence)) |> 
  gg_histogram(
    x = flipper_length_mm,
    facet = species,
    facet2 = sex,
    binwidth = 2
  )
p
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

canvasXpress(p, width = 672, height = 500)
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

Unspecified titles converted to snakecase::sentence_case

p <- diamonds |>
  gg_hex(
    coord = coord_cartesian(clip = "on"), 
    x = carat,
    y = price,
    y_limits = c(0, 20000),
  )
## Scale for y is already present.
## Adding another scale for y, which will replace the existing scale.
p

canvasXpress(p, width = 672, height = 500)

Prefixed arguments to customise x, y, col and facet properties

p <- penguins |>
  drop_na(sex) |>  
  gg_jitter(
    x = species,
    y = body_mass_g,
    col = flipper_length_mm,
    facet = sex,
    x_labels = \(x) str_sub(x, 1, 1),
    y_breaks = scales::breaks_width(1000),
    y_expand_limits = 2000,
    y_labels = scales::label_number(big.mark = " "), 
    y_transform = "log10",
    y_title = "Body mass (g)",
    col_steps = TRUE,
    col_breaks = \(x) quantile(x, seq(0, 1, 0.25)),
    col_pal = viridisLite::rocket(n = 9, direction = -1),
    facet_labels = str_to_sentence,
  )
## Warning in gg_blanket(data = data, geom = "point", stat = stat, position =
## position, : Ignoring unknown parameters: `y_title` and `col_pal`
p

canvasXpress(p, width = 672, height = 500)

Access to other geom_* arguments via …

p <- penguins |>
  mutate(across(sex, str_to_sentence)) |> 
  drop_na(sex) |> 
  gg_smooth(
    x = flipper_length_mm,
    y = body_mass_g,
    col = sex, 
    col_pal = c("#003f5c", "#ffa600"),
    colour = "#bc5090", 
    linewidth = 1, 
    linetype = "dashed",
    alpha = 1, 
    se = TRUE, 
    level = 0.999, 
  )
## Warning in gg_blanket(data = data, geom = "smooth", stat = stat, position =
## position, : Ignoring unknown parameters: `col_pal`
p
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

canvasXpress(p, width = 672, height = 500)
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
p <- penguins |> 
  gg_boxplot(
    y = island, 
    x = flipper_length_mm, 
    col = species,
    fill = NA,
    position = position_dodge2(preserve = "single")
  ) 
p
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_boxplot()`).

canvasXpress(p, width = 672, height = 500)
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_boxplot()`).

Access other aesthetics via mapping

p <- penguins |> 
  gg_jitter(
    y = species, 
    x = flipper_length_mm, 
    col = species,
    mapping = aes(alpha = species, shape = species),
  ) +
  scale_alpha_manual(values = c(0.33, 1, 0.33)) +
  guides(alpha = guide_legend(reverse = TRUE))
p
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_point()`).

canvasXpress(p, width = 672, height = 500)

Families of mode themes that differ by legend placement

p <- penguins |>
  gg_histogram(
    x = flipper_length_mm,
    col = species,
    title = "Penguin flipper length by species",
    subtitle = "Palmer Archipelago, Antarctica",
    caption = "Source: Gorman, 2020", 
    mode = light_mode_t(),
    binwidth = 2
  ) +
  labs(colour = NULL, fill = NULL)
p
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

canvasXpress(p, width = 672, height = 500)
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).
p <- penguins |>
  gg_histogram(
    x = flipper_length_mm,
    col = species,
    title = "Penguin flipper length by species",
    subtitle = "Palmer Archipelago, Antarctica",
    caption = "Source: Gorman, 2020", 
    mode = grey_mode_b(),
    binwidth = 2
  )
p
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

canvasXpress(p, width = 672, height = 500)
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).
p <- penguins |>
  gg_histogram(
    x = flipper_length_mm,
    col = species,
    title = "Penguin flipper length by species",
    subtitle = "Palmer Archipelago, Antarctica",
    caption = "Source: Gorman, 2020", 
    mode = dark_mode_r(),
    binwidth = 2
  )
p
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

canvasXpress(p, width = 672, height = 500)
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

Set the mode and geom defaults with set_blanket

set_blanket(grey_mode_r(), "#ffa600")
p <- penguins |>
  gg_point(
    x = flipper_length_mm, 
    y = body_mass_g,
    x_breaks = scales::breaks_pretty(3),
  ) +
  geom_vline(xintercept = 200) +
  annotate("text", x = I(0.25), y = I(0.75), label = "Here")
p
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_point()`).

canvasXpress(p, width = 672, height = 500)
p <- penguins |> 
  gg_histogram(
    x = flipper_length_mm,
    x_breaks = scales::breaks_pretty(3),
    binwidth = 2
  ) +
  geom_vline(xintercept = 200) +
  annotate("text", x = I(0.75), y = I(0.75), label = "Here")
p
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

canvasXpress(p, width = 672, height = 500)
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).
set_blanket(dark_mode_r(), geom_colour = "#bc5090", annotate_colour = darkness[1])

p1 <- penguins |>
  gg_point(
    x = flipper_length_mm, 
    y = body_mass_g,
    x_breaks = scales::breaks_pretty(3),
  ) +
  geom_vline(xintercept = 200) +
  annotate("text", x = I(0.25), y = I(0.75), label = "Here")
p2 <- penguins |> 
  gg_histogram(
    x = flipper_length_mm,
    x_breaks = scales::breaks_pretty(3),
    binwidth = 2
  ) +
  geom_vline(xintercept = 200) +
  annotate("text", x = I(0.75), y = I(0.75), label = "Here")
p = p1 + p2
p
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_point()`).
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

canvasXpress(p, width = 672, height = 500)
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

No Facet

set_blanket(colour = orange)

p1 <- penguins |>
  gg_point(
    x = flipper_length_mm,
    y = body_mass_g,
    col = island
  )
p
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_point()`).
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

canvasXpress(p, width = 672, height = 500)
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).
p <- penguins |>
  gg_bar(
    x = sex,
    col = island
  )
p

canvasXpress(p, width = 672, height = 500)
p <- penguins |>
  gg_histogram(
    x = flipper_length_mm,
    col = island,
    binwidth = 2
  )
p
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

canvasXpress(p, width = 672, height = 500)
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

Facet

set_blanket(colour = orange)

p <- penguins |>
  gg_point(
    x = flipper_length_mm,
    y = body_mass_g,
    col = island,
    facet = species
  )
p
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_point()`).

canvasXpress(p, width = 672, height = 500)
p <- penguins |>
  gg_bar(
    x = sex,
    col = island,
    facet = species
  )
p

canvasXpress(p, width = 672, height = 500)
p <- penguins |>
  gg_histogram(
    x = flipper_length_mm,
    col = island,
    facet = species,
    binwidth = 2
  )
p
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

canvasXpress(p, width = 672, height = 500)
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_bin()`).

Update Geom Defaults

update_geom_defaults("boxplot",
                     aes(colour = "red", 
                         fill = "blue", 
                         alpha = 0.5, 
                         linewidth = 0.66)
                     )
p <- penguins |> 
  ggplot(aes(x = species, y = body_mass_g)) +
  geom_boxplot() 
p
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_boxplot()`).

canvasXpress::canvasXpress(p)
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_boxplot()`).

Senssion Info

sessionInfo()
## R version 4.4.0 (2024-04-24)
## Platform: aarch64-apple-darwin20
## Running under: macOS 15.5
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib 
## LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## time zone: America/New_York
## tzcode source: internal
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] canvasXpress_1.50.5  patchwork_1.2.0      palmerpenguins_0.1.1
## [4] tidyr_1.3.1          stringr_1.5.1        dplyr_1.1.4         
## [7] ggplot2_3.5.2        ggblanket_9.0.0     
## 
## loaded via a namespace (and not attached):
##  [1] sass_0.4.10        generics_0.1.4     stringi_1.8.7      lattice_0.22-6    
##  [5] hms_1.1.3          digest_0.6.37      magrittr_2.0.3     evaluate_1.0.4    
##  [9] grid_4.4.0         timechange_0.3.0   RColorBrewer_1.1-3 fastmap_1.2.0     
## [13] Matrix_1.7-0       jsonlite_2.0.0     mgcv_1.9-1         purrr_1.0.4       
## [17] viridisLite_0.4.2  scales_1.4.0       jquerylib_0.1.4    cli_3.6.5         
## [21] labelled_2.13.0    rlang_1.1.6        splines_4.4.0      withr_3.0.2       
## [25] cachem_1.1.0       yaml_2.3.10        tools_4.4.0        colorspace_2.1-1  
## [29] forcats_1.0.0      vctrs_0.6.5        R6_2.6.1           lifecycle_1.0.4   
## [33] lubridate_1.9.3    snakecase_0.11.1   htmlwidgets_1.6.4  pkgconfig_2.0.3   
## [37] pillar_1.10.2      bslib_0.9.0        hexbin_1.28.3      gtable_0.3.6      
## [41] glue_1.8.0         haven_2.5.4        xfun_0.52          tibble_3.3.0      
## [45] tidyselect_1.2.1   rstudioapi_0.16.0  knitr_1.50         farver_2.1.2      
## [49] nlme_3.1-164       htmltools_0.5.8.1  rmarkdown_2.29     labeling_0.4.3    
## [53] compiler_4.4.0