如何使用上标与ggplot2

sar*_*ara 15 r ggplot2

如何在x轴上打印埃方形?我尝试如下.我真的很抱歉我的简单问题.

labs(x = "x axis" (Å^2)", y = "y axis")
Run Code Online (Sandbox Code Playgroud)

akr*_*run 14

我们可以用 bquote

library(ggplot2)
ggplot(mtcars, aes(hp, mpg)) + 
       geom_point() +
       labs(x = bquote('x axis'~(Å^2)), y = "y axis") +
       #or
       #labs(x = bquote('x axis'~(ring(A)^2)), y = "y axis") 
       theme_bw()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • @sara只需添加`bold`就像`bquote(粗体('x轴'〜(Å^ 2))`或`表达式(粗体(x~轴〜环(A)^ 2))` (2认同)
  • @zyurnaiidi 感谢您的评论。正方形(上标)不是粗体字母。 (2认同)

zyu*_*idi 13

您应该使用表达式,最好结合使用粘贴,如下所示:

ggplot(mtcars, aes(hp, mpg)) + geom_point() + labs(x = expression(paste("x axis ", ring(A)^2)), y = "y axis")
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述