【问题标题】:How to use unicode characters and greek letters together in an annotate element of a plot made with ggplot2?如何在使用 ggplot2 制作的绘图的注释元素中一起使用 unicode 字符和希腊字母?
【发布时间】:2021-07-28 09:29:02
【问题描述】:

我想用annotate写1

library(ggplot2)

# Only greek letters

ggplot() +
  annotate(geom = "text",
           label = "1*alpha*beta*t",
           parse = TRUE,
           x = 0,
           y = 0)

# Greek letters + unicode

ggplot() +
  annotate(geom = "text",
           label = "1* \U226A *alpha*beta*t",
           parse = TRUE,
           x = 0,
           y = 0)

Error in parse(text = text[[i]]) : <text>:1:4: unexpected input
1: 1* «
       ^

【问题讨论】:

    标签: r ggplot2 unicode annotations annotate


    【解决方案1】:
    ggplot() +
      annotate(geom = "text",
               label = as.character(expression(paste("1 << ",alpha, beta))),
               parse = TRUE,
               x = 0,
               y = 0)
    

    或者这样

    ggplot() +
      annotate(geom = "text",
               label = as.character(expression(paste("1","\U226A", alpha, beta))),
               parse = TRUE, size = 5,
               x = 0,
               y = 0)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-19
      • 1970-01-01
      • 2018-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-14
      相关资源
      最近更新 更多