在多ggboxplot中重命名因子变量
Rename factor variable in multi ggboxplot
下面的代码创建了两个并排的箱形图,标题为“pun”和“mv”。如何将标题改为“惩罚”和“道德”?
ggboxplot(d, x = "Condition.Name",
y = c("pun", "mv"),
combine = TRUE,
color = c("#0073C2FF", "#EFC000FF", "#0073C2FF", "#EFC000FF"),
xlab = 'Condition',
ylab = 'Total score'
最简单的方法是传递一个修改了列名的数据版本。
以下内容很好地复制了您自己的设置:
library(ggpubr)
set.seed(1)
d <- data.frame(Condition.Name = rep(c("Breakfast", "No Breakfast"), 100),
pun = rnorm(200, 100, 10),
mv = rnorm(200, 98, 10))
所以使用您自己的绘图代码,我们得到了与您的类似的绘图:
ggboxplot(d, x = "Condition.Name",
y = c("pun", "mv"),
combine = TRUE,
color = c("#0073C2FF", "#EFC000FF", "#0073C2FF", "#EFC000FF"),
xlab = 'Condition',
ylab = 'Total score'
)
要更改它,我们只需重命名我们传递给 ggboxplot
的 d
副本中的列。最简单的方法可能是 dplyr::rename
:
ggboxplot(dplyr::rename(d, Punishment = pun, Morality = mv),
x = "Condition.Name",
y = c("Punishment", "Morality"),
combine = TRUE,
color = c("#0073C2FF", "#EFC000FF", "#0073C2FF", "#EFC000FF"),
xlab = 'Condition',
ylab = 'Total score'
)
由 reprex package (v0.3.0)
于 2020-12-14 创建
下面的代码创建了两个并排的箱形图,标题为“pun”和“mv”。如何将标题改为“惩罚”和“道德”?
ggboxplot(d, x = "Condition.Name",
y = c("pun", "mv"),
combine = TRUE,
color = c("#0073C2FF", "#EFC000FF", "#0073C2FF", "#EFC000FF"),
xlab = 'Condition',
ylab = 'Total score'
最简单的方法是传递一个修改了列名的数据版本。
以下内容很好地复制了您自己的设置:
library(ggpubr)
set.seed(1)
d <- data.frame(Condition.Name = rep(c("Breakfast", "No Breakfast"), 100),
pun = rnorm(200, 100, 10),
mv = rnorm(200, 98, 10))
所以使用您自己的绘图代码,我们得到了与您的类似的绘图:
ggboxplot(d, x = "Condition.Name",
y = c("pun", "mv"),
combine = TRUE,
color = c("#0073C2FF", "#EFC000FF", "#0073C2FF", "#EFC000FF"),
xlab = 'Condition',
ylab = 'Total score'
)
要更改它,我们只需重命名我们传递给 ggboxplot
的 d
副本中的列。最简单的方法可能是 dplyr::rename
:
ggboxplot(dplyr::rename(d, Punishment = pun, Morality = mv),
x = "Condition.Name",
y = c("Punishment", "Morality"),
combine = TRUE,
color = c("#0073C2FF", "#EFC000FF", "#0073C2FF", "#EFC000FF"),
xlab = 'Condition',
ylab = 'Total score'
)
由 reprex package (v0.3.0)
于 2020-12-14 创建