Load data and Libraries

https://r4ds.had.co.nz/data-visualisation.html

if (!("ggplot2" %in% installed.packages())) {
    install.packages('ggplot2')
}
library('ggplot2')
## Warning: package 'ggplot2' was built under R version 4.4.1
if (!("ggthemes" %in% installed.packages())) {
    install.packages('ggthemes')
}
library('ggthemes')
if (!("devtools" %in% installed.packages())) {
    install.packages('devtools')
}
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('canvasXpress')

Example Plot

mtcars2 <- within(mtcars, {
  vs <- factor(vs, labels = c("V-shaped", "Straight"))
  am <- factor(am, labels = c("Automatic", "Manual"))
  cyl  <- factor(cyl)
  gear <- factor(gear)
})

p <- ggplot(mtcars2) +
     geom_point(aes(x = wt, y = mpg, colour = gear)) +
     labs(
       title = "Fuel economy declines as weight increases",
       subtitle = "(1973-74)",
       caption = "Data from the 1974 Motor Trend US magazine.",
       x = "Weight (1000 lbs)",
       y = "Fuel economy (mpg)",
       colour = "Gears"
     )

Default

p

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

Economist

pe <- p + theme_economist() + scale_colour_economist()
pe

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

Excel

pe <- p + theme_excel() + scale_colour_excel()
pe

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

igray

pi <- p + theme_igray()
pi

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

Solarized

ps <- p + theme_solarized() + scale_colour_solarized()
ps

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

Solarized ligth FALSE

ps <- p + theme_solarized(light = FALSE) + scale_colour_solarized()
ps

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

Tufte

pt <- p + theme_tufte()
pt

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

Color blind

cb <- p + scale_color_colorblind()
cb

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

Paul Tol

pt <- p + scale_color_ptol() + theme_minimal()
pt

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

Wall Stree Journal

pw <- p + theme_wsj(base_size = 8) + scale_color_wsj()
pw

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

Tableau

pt <- p + scale_color_tableau()
pt

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

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 ggthemes_5.1.0      ggplot2_3.5.2      
## 
## loaded via a namespace (and not attached):
##  [1] vctrs_0.6.5        cli_3.6.5          knitr_1.50         rlang_1.1.6       
##  [5] xfun_0.52          stringi_1.8.7      purrr_1.0.4        generics_0.1.4    
##  [9] jsonlite_2.0.0     labeling_0.4.3     glue_1.8.0         htmltools_0.5.8.1 
## [13] sass_0.4.10        scales_1.4.0       rmarkdown_2.29     grid_4.4.0        
## [17] evaluate_1.0.4     jquerylib_0.1.4    tibble_3.3.0       fastmap_1.2.0     
## [21] yaml_2.3.10        lifecycle_1.0.4    stringr_1.5.1      compiler_4.4.0    
## [25] dplyr_1.1.4        RColorBrewer_1.1-3 htmlwidgets_1.6.4  pkgconfig_2.0.3   
## [29] rstudioapi_0.16.0  farver_2.1.2       digest_0.6.37      R6_2.6.1          
## [33] tidyselect_1.2.1   pillar_1.10.2      magrittr_2.0.3     bslib_0.9.0       
## [37] withr_3.0.2        tools_4.4.0        gtable_0.3.6       cachem_1.1.0