library(ggplot2)
library(patchwork)
Prerequisites
To access the datasets, help pages, and functions that we will use in this code snippet, load the following packages:
Then make some data and ggplot2 plots to be used in the patchwork.
<- data.frame(year = 1875:1972, level = as.vector(LakeHuron))
huron <- ggplot(huron, aes(year))
h
<- h +
h1 geom_ribbon(aes(ymin = level - 1, ymax = level + 1), fill = "grey70") +
geom_line(aes(y = level))
<- h + geom_area(aes(y = level)) h2
Michael McCarthy
Thanks for reading! I’m Michael, the voice behind Tidy Tales. I am an award winning data scientist and R programmer with the skills and experience to help you solve the problems you care about. You can learn more about me, my consulting services, and my other projects on my personal website.
Session Info
─ Session info ───────────────────────────────────────────────────────────────
setting value
version R version 4.2.2 (2022-10-31)
os macOS Mojave 10.14.6
system x86_64, darwin17.0
ui X11
language (EN)
collate en_CA.UTF-8
ctype en_CA.UTF-8
tz America/Vancouver
date 2022-12-22
pandoc 2.14.0.3 @ /Applications/RStudio.app/Contents/MacOS/pandoc/ (via rmarkdown)
quarto 1.2.280 @ /usr/local/bin/quarto
─ Packages ───────────────────────────────────────────────────────────────────
package * version date (UTC) lib source
ggplot2 * 3.4.0 2022-11-04 [1] CRAN (R 4.2.0)
patchwork * 1.1.2 2022-08-19 [1] CRAN (R 4.2.0)
sessioninfo * 1.2.2 2021-12-06 [1] CRAN (R 4.2.0)
[1] /Users/Michael/Library/R/x86_64/4.2/library/__tidytales
[2] /Library/Frameworks/R.framework/Versions/4.2/Resources/library
──────────────────────────────────────────────────────────────────────────────
Reuse
Citation
BibTeX citation:
@online{mccarthy2022,
author = {Michael McCarthy},
title = {Shared Axis Labels in Patchwork Plots},
date = {2022-12-22},
url = {https://tidytales.ca/snippets/2022-12-22_patchwork-shared-axis-labels},
langid = {en}
}
For attribution, please cite this work as:
Michael McCarthy. (2022, December 22). Shared axis labels in
patchwork plots. https://tidytales.ca/snippets/2022-12-22_patchwork-shared-axis-labels
Comments