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

Reuse

Text and figures are licensed under Creative Commons Attribution CC BY 4.0. 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/dewitt_blog/posts/2019-04-03-latex-in-ggplot2/

BibTeX citation

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