ggplot2 latex trick
This is a useful package to use latex notation in {ggplot2
}. I saw this on twitter and wish I had written down the originator for proper citation but I forgot at the time.
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
✓ ggplot2 3.3.5.9000 ✓ purrr 0.3.4.9000
✓ tibble 3.1.6.9001 ✓ dplyr 1.0.8.9000
✓ tidyr 1.1.4.9000 ✓ stringr 1.4.0.9000
✓ readr 2.1.2 ✓ forcats 0.5.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
x dplyr::filter() masks stats::filter()
x dplyr::lag() masks stats::lag()
library (latex2exp)
example_data <- tibble (ability = seq (- 3 ,3 , .1 )) %>%
mutate (result = plogis (ability* 2 ))
example_data %>%
ggplot (aes (ability, result))+
geom_line ()+
labs (
x = TeX ("$ability( \\ theta)$" )
)+
theme_bw ()
Citation BibTeX citation:
@online{dewitt2019,
author = {Michael DeWitt},
title = {Latex in Ggplot2},
date = {2019-04-03},
url = {https://michaeldewittjr.com/programming/2019-04-03-latex-in-ggplot2},
langid = {en}
}
For attribution, please cite this work as: