如何在x轴上打印埃平方?我尝试如下。
labs(x = "x axis" (Å^2)", y = "y axis")
您可以简单地使用:
ggplot(mtcars, aes(hp, mpg)) + geom_point() + labs(x = x~axis~ring(A)^2, y = "y axis")
另一个选择是使用 ggtext 包。它允许使用 markdown 标签,我发现这样更容易编写和阅读。
library(ggtext)
library(ggplot2)
ggplot(mtcars, aes(hp, mpg)) +
labs(x = "x axis (Å^(2))", y = "y axis") +
## use markdown theme for simple superscripts
theme(axis.title.x = element_markdown())
由 reprex 包于 2022 年 7 月 14 日创建(v2.0.1)
使用 < sup> 2 < /sup> (无空格)代替 ^ ,它应该可以工作! https://cran.r-project.org/web/packages/ggtext/vignettes/theme_elements.html