如何在使用 ggplot2 制作的绘图的注释元素中一起使用 unicode 字符和希腊字母?

问题描述

我想用annotate写1

library(ggplot2)

# Only greek letters

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

enter image description here

# Greek letters + unicode

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

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

解决方法

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

enter image description here 或者这样

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

enter image description here