Last active
April 11, 2024 23:09
-
-
Save benmarwick/5cfeda1d20ff9ab3231a5de8fac36213 to your computer and use it in GitHub Desktop.
ggplot axis labels with superscript and subscript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
# using expression() for the text formatting: | |
ggplot(mtcars, | |
aes(disp, | |
mpg)) + | |
geom_point() + | |
# ~ for spaces, and * for no-space between (unquoted) expressions | |
ylab(expression(Anthropogenic~SO[4]^{"2-"}~(ngm^-3))) + | |
xlab(expression(italic(delta)^13*C[ap]*"‰")) + | |
theme_bw(base_size = 16) | |
# using markdown for the text formatting: | |
library(ggtext) | |
ggplot(mtcars, | |
aes(disp, | |
mpg)) + | |
geom_point() + | |
ylab("Anthropogenic SO<sub>4</sub><sup>2-</sup> (ngm<sup>-3</sup>)") + | |
xlab("*δ*<sup>18</sup>O (‰ VPDB)") + | |
theme(axis.title.x = element_markdown(), | |
axis.title.y = element_markdown()) | |
theme_bw(base_size = 16) | |
# write in Quarto to get per mille unicode symbol to show up on PDF output | |
```{r} | |
#| fig.showtext = TRUE | |
library(showtext) | |
ggplot(mtcars, | |
aes(disp, | |
mpg)) + | |
geom_point() + | |
ylab(expression(Anthropogenic~SO[4]^{"2-"}~(ngm^-3))) + | |
xlab(expression(italic(delta)^13*C[ap]*"‰")) + | |
theme_bw(base_size = 16) | |
``` |
Author
benmarwick
commented
Jul 6, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment