Latex in ggplot2

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.

library(tidyverse)
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("Error in rendering LaTeX")
  )+
  theme_bw()

plogis(3)
[1] 0.9525741
exp(3)/(1+exp(3))
[1] 0.9525741

Citation

BibTex citation:

@online{dewitt2019
author = {Michael E. DeWitt},
title = {Latex in ggplot2},
date = 2019-04-03,
url = {https://michaeldewittjr.com/articles/2019-04-03-latex-in-ggplot2},
langid = {en}
}

For attribution, please cite this work as:

Michael E. DeWitt. 2019. "Latex in ggplot2." April 3, 2019. https://michaeldewittjr.com/articles/2019-04-03-latex-in-ggplot2