将上标添加到 R 中的 ggbarplot y 轴
Add superscript to ggbarplot y axis in R
我已经尝试了几个不同的选项,但我总是收到错误消息。我正在尝试为标题“消耗的表面积 (cm^2)”添加上标,这是最近的尝试。
ggbarplot(sr, x = "Treatment", y = "SA30",
add = "mean_sd",
color = c("chartreuse","chartreuse"), add.params = list(size = 2),
fill = "Treatment", palette = c("chartreuse3","chartreuse4"),
ylab = expression("Surface Area Consumed (cm"^2")"), xlab = "", legend = "", legend.title = "") +
scale_y_continuous(expand = c(0, 0), breaks=seq(0,20,2)) +
coord_cartesian(ylim=c(0,14)) +
rremove("ticks") +
rotate_y_text(45) +
font("xy.text", color = "seagreen") +
theme(axis.text.x = element_text(size = 20),
axis.text.y = element_text(size = 15),
axis.title.x = element_text(size = 30),
axis.title.y = element_text(size = 20, color = "seagreen"),
text=element_text(family="Tw Cen MT Condensed Extra Bold", size=12),
axis.line = element_line(size = 2, color = "seagreen"))
Example graph with different yaxis title
我收到了这个错误:
Error: Cannot add ggproto objects together. Did you forget to add this object to a ggplot object?
如有任何帮助,我们将不胜感激。
我认为问题出在您的代码中 2 后面缺少波浪号。我在下面提供了一个使用确切预期文本的 ylabel 的可重现示例。
如果我理解正确的话,创建的 ggplot 对象之后可以修改标签。我会更改附加实验室功能中的标签来对此进行测试。
library(tidyverse)
mtcars %>%
ggplot(aes(x = cyl, y = mpg)) +
geom_point() +
labs(y = expression("Surface Area Consumed (cm"^{2}~")"))
由 reprex package (v2.0.0)
于 2021-04-05 创建
我已经尝试了几个不同的选项,但我总是收到错误消息。我正在尝试为标题“消耗的表面积 (cm^2)”添加上标,这是最近的尝试。
ggbarplot(sr, x = "Treatment", y = "SA30",
add = "mean_sd",
color = c("chartreuse","chartreuse"), add.params = list(size = 2),
fill = "Treatment", palette = c("chartreuse3","chartreuse4"),
ylab = expression("Surface Area Consumed (cm"^2")"), xlab = "", legend = "", legend.title = "") +
scale_y_continuous(expand = c(0, 0), breaks=seq(0,20,2)) +
coord_cartesian(ylim=c(0,14)) +
rremove("ticks") +
rotate_y_text(45) +
font("xy.text", color = "seagreen") +
theme(axis.text.x = element_text(size = 20),
axis.text.y = element_text(size = 15),
axis.title.x = element_text(size = 30),
axis.title.y = element_text(size = 20, color = "seagreen"),
text=element_text(family="Tw Cen MT Condensed Extra Bold", size=12),
axis.line = element_line(size = 2, color = "seagreen"))
Example graph with different yaxis title
我收到了这个错误:
Error: Cannot add ggproto objects together. Did you forget to add this object to a ggplot object?
如有任何帮助,我们将不胜感激。
我认为问题出在您的代码中 2 后面缺少波浪号。我在下面提供了一个使用确切预期文本的 ylabel 的可重现示例。
如果我理解正确的话,创建的 ggplot 对象之后可以修改标签。我会更改附加实验室功能中的标签来对此进行测试。
library(tidyverse)
mtcars %>%
ggplot(aes(x = cyl, y = mpg)) +
geom_point() +
labs(y = expression("Surface Area Consumed (cm"^{2}~")"))
由 reprex package (v2.0.0)
于 2021-04-05 创建