1

I need to label the axis of my plot using variables within expression because I will add superscripts.

axis_label <- "some axis label"

mtcars %>% 
  ggplot(aes(mpg, cyl)) +
  geom_point() +
  scale_y_continuous(
    name = axis_label
  )

This does not work: (I need to evaluate the variable axis_label)

mtcars %>% 
  ggplot(aes(mpg, cyl)) +
  geom_point() +
  scale_y_continuous(
    name = expression(axis_label^2)
  )

I am using this page, it does not solve my problem: https://github.com/tidyverse/ggplot2/wiki/Plotmath

Alvaro Morales
  • 1,845
  • 3
  • 12
  • 21

0 Answers0