如何根据一个因素设置ggboxplot mean_sd形状?

问题描述 投票:0回答:1

我正在尝试用具有 25 个因子的变量之一使用不同的形状来表示一个多变量数据集(ggplot2 有这么多可用的形状)。 我将使用 iris 数据集作为可重现的示例

library(tidyverse)
library(ggpubr)
data(iris)

iris_pivot <- pivot_longer(iris, col = 1:4, names_to = "parameter")

ggboxplot(data = iris_pivot, x = "parameter", y = "value",
    add = "mean_sd", add.params = list(color = "Species"),
     legend = c("right"))

导致以下情节

我尝试在add.parameter中设置形状并使用

scale_shape_manual
但没有成功。

ggboxplot(data = iris_pivot, x = "parameter", y = "value",
add = "mean_sd", add.params = list(color = "Species", shape = "Species"), legend = c("right"))

即使不使用ggpubr

,我们也会感谢所有帮助
r shapes boxplot ggpubr
1个回答
0
投票

您可以将

aes(shape = Species)
添加到linerange层:

p <- ggboxplot(data = iris_pivot, x = "parameter", y = "value",
          add = "mean_sd", add.params = list(color = "Species",
                                             size = 1),
          legend = c("right")) 

p$layers[[2]]$mapping <- aes(colour = Species, shape = Species)

p

© www.soinside.com 2019 - 2024. All rights reserved.