How can I make `bquote` replace the greek letter stored in a variable with the symbol?

前端 未结 1 852
遇见更好的自我
遇见更好的自我 2021-01-28 02:32

I want to label the axis on a plot dynamically. The labels come from a data frame and contain greek letters as well as super/sub scription.

In a static case, where I wou

相关标签:
1条回答
  • 2021-01-28 03:06

    Turn the a and b variable into symbols with rlang::sym.

    library("tidyverse")
    
    a <- "alpha"
    b <- "beta"
    
    ggplot(data.frame(x = c(1), y = c(1)), aes(x, y)) +
      geom_point() +
      labs(x = bquote(.(sym(a))[.(sym(b))])) +
      labs(y = bquote(alpha[beta]))
    

    Created on 2019-11-04 by the reprex package (v0.3.0)

    0 讨论(0)
提交回复
热议问题