Latex in ggplot2

This is a quick overview of a trick to add LaTex in ggplot2.

Michael DeWitt https://michaeldewittjr.com
04-03-2019

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("$ability(\\theta)$")
  )+
  theme_bw()


plogis(3)

[1] 0.9525741

exp(3)/(1+exp(3))

[1] 0.9525741

Corrections

If you see mistakes or want to suggest changes, please create an issue on the source repository.

Reuse

Text and figures are licensed under Creative Commons Attribution CC BY 4.0. Source code is available at https://github.com/medewitt/medewitt.github.io, unless otherwise noted. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".

Citation

For attribution, please cite this work as

DeWitt (2019, April 3). Michael DeWitt: Latex in ggplot2. Retrieved from https://michaeldewittjr.com/programming/2019-04-03-latex-in-ggplot2/

BibTeX citation

@misc{dewitt2019latex,
  author = {DeWitt, Michael},
  title = {Michael DeWitt: Latex in ggplot2},
  url = {https://michaeldewittjr.com/programming/2019-04-03-latex-in-ggplot2/},
  year = {2019}
}