ggplot轴标签r中的撇号和上标

问题描述

可重现的例子:

x1<-rnorm(5,5,1)
y1<-rnorm(5,1)
d<-data.frame(x1,y1)

ggplot(data=d,aes(x=x1,y=y1))+
  geom_point()+
  ylab(bquote('y (since year s'* ~ 1^st*' day)'))

我想在“年份”之后添加一个撇号,我尝试添加 '\\'' 但它不起作用。

已经有几个关于上标的问题了:

Subscripts and superscripts "-" or "+" with ggplot2 axis labels? (ionic chemical notation)

How to write chemical formulas in ggplot

ggplot labels adding superscript,how to come out of the superscript?

但我找不到任何将它与撇号(由上标表达式识别)组合的内容

解决方法

单引号 ' 和双引号 " 在 R 代码中通常可以互换。通过用双引号将包含它的字符串括起来来获取所需的单引号。

library(ggplot2)
x1<-rnorm(5,5,1)
y1<-rnorm(5,1)
d<-data.frame(x1,y1)

ggplot(data=d,aes(x=x1,y=y1))+
  geom_point()+
  ylab(bquote("y (since year's"* ~ 1^st*' day)'))

reprex package (v0.3.0) 于 2021 年 1 月 2 日创建