Intro Thoughts
Status Quo
library(ggplot2)
ggplot(cars) +
aes(speed, dist) +
geom_point()

last_plot() +
theme(panel.grid = element_line(color = "black"))

last_plot() +
theme_classic()

last_plot() +
theme(panel.grid = element_line(color = "black"))

last_plot() +
theme(panel.grid.major = element_line(color = "black"))

last_plot()$theme$panel.grid
## List of 7
## $ colour : chr "black"
## $ linewidth : NULL
## $ linetype : NULL
## $ lineend : NULL
## $ arrow : logi FALSE
## $ arrow.fill : chr "black"
## $ inherit.blank: logi FALSE
## - attr(*, "class")= chr [1:2] "element_line" "element"
last_plot()$theme$panel.grid.minor
## list()
## - attr(*, "class")= chr [1:2] "element_blank" "element"
last_plot()$theme$panel.grid.major
## List of 7
## $ colour : chr "black"
## $ linewidth : NULL
## $ linetype : NULL
## $ lineend : NULL
## $ arrow : logi FALSE
## $ arrow.fill : chr "black"
## $ inherit.blank: logi FALSE
## - attr(*, "class")= chr [1:2] "element_line" "element"
sessionInfo("ggplot2")
## R version 4.4.0 (2024-04-24)
## Platform: x86_64-apple-darwin20
## Running under: macOS Monterey 12.7.6
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.4-x86_64/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/Denver
## tzcode source: internal
##
## attached base packages:
## character(0)
##
## other attached packages:
## [1] ggplot2_3.5.1.9000
##
## loaded via a namespace (and not attached):
## [1] vctrs_0.6.5 cli_3.6.3 knitr_1.49 rlang_1.1.5
## [5] xfun_0.50 generics_0.1.3 jsonlite_1.8.8 labeling_0.4.3
## [9] glue_1.8.0 colorspace_2.1-1 htmltools_0.5.8.1 sass_0.4.9
## [13] methods_4.4.0 fansi_1.0.6 datasets_4.4.0 scales_1.3.0
## [17] rmarkdown_2.26 grid_4.4.0 tibble_3.2.1 evaluate_0.23
## [21] munsell_0.5.1 jquerylib_0.1.4 fastmap_1.1.1 yaml_2.3.8
## [25] lifecycle_1.0.4 utils_4.4.0 compiler_4.4.0 dplyr_1.1.4
## [29] pkgconfig_2.0.3 rstudioapi_0.16.0 base_4.4.0 stats_4.4.0
## [33] graphics_4.4.0 farver_2.1.2 digest_0.6.35 R6_2.5.1
## [37] tidyselect_1.2.1 utf8_1.2.4 pillar_1.9.0 magrittr_2.0.3
## [41] bslib_0.7.0 withr_3.0.2 tools_4.4.0 grDevices_4.4.0
## [45] gtable_0.3.6 cachem_1.0.8
Experiment
theme_classic2 <- function(base_size = 11, base_family = "",
header_family = NULL,
base_line_size = base_size / 22,
base_rect_size = base_size / 22,
ink = "black", paper = "white") {
theme_bw(
base_size = base_size,
base_family = base_family,
header_family = header_family,
base_line_size = base_line_size,
base_rect_size = base_rect_size,
ink = ink, paper = paper
) %+replace%
theme(
# no background and no grid
panel.border = element_blank(),
panel.grid = element_blank(), # Revision
# show axes
axis.text = element_text(size = rel(0.8)),
axis.line = element_line(lineend = "square"),
axis.ticks = element_line(),
# simple, black and white strips
strip.background = element_rect(linewidth = rel(2)),
# NB: size is 1 but clipped, it looks like the 0.5 of the axes
complete = TRUE
)
}
ggplot(cars) +
aes(speed, dist) +
geom_point()

last_plot() +
theme(panel.grid = element_line(color = "black"))

last_plot() +
theme_classic2()

last_plot() +
theme(panel.grid = element_line(color = "black"))

theme_blank <- function(base_size = 11, base_family = "",
header_family = NULL,
base_line_size = base_size / 22,
base_rect_size = base_size / 22,
ink = "black", paper = alpha(ink, 0)) {
force(ink)
# Based on theme_bw
theme_grey(
base_size = base_size,
base_family = base_family,
header_family = header_family,
base_line_size = base_line_size,
base_rect_size = base_rect_size,
ink = ink, paper = paper
) %+replace%
theme(
panel.background = element_blank(),
# plot.background = element_blank(),
legend.background = element_blank(),
legend.key = element_blank(),
panel.border = element_blank(),
panel.grid = element_blank(),
axis.title = element_blank(),
axis.ticks = element_blank(),
axis.text = element_blank(),
# contour strips to match panel contour
strip.background = element_blank(),
complete = TRUE,
plot.margin = margin(10,10,10,10, unit = "pt")
)
}
library(ggplot2)
ggplot(mtcars) +
aes(wt, mpg) +
geom_point() +
facet_wrap(~am) +
theme_transparent()
last_plot() +
theme_void(paper = "pink") +
labs(title = "theme void")
last_plot() +
theme_blank(paper = "grey") +
labs(title = "theme blank loves infographics")


