【问题标题】:Apostrophe and superscript in ggplot axis label rggplot轴标签r中的撇号和上标
【发布时间】:2021-01-02 11:22:22
【问题描述】:

可重现的例子:

x1<-rnorm(5,5,1)
y1<-rnorm(5,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 ggplot2 apostrophe superscript


    【解决方案1】:

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

    library(ggplot2)
    x1<-rnorm(5,5,1)
    y1<-rnorm(5,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-01-02 创建

    【讨论】:

    • 谢谢,这很容易。我试过了,但我一定搞砸了别的东西,认为它不起作用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-26
    • 2021-07-31
    • 1970-01-01
    • 1970-01-01
    • 2020-08-19
    • 2023-03-27
    相关资源
    最近更新 更多