我有这个数据框
set.seed(1234)
x <- rnorm(80, 5, 1)
df <- data.frame(groups = c(rep("group1",20),
rep("group2",20),
rep("group3",20),
rep("group4",20)),
value = x,
type = c(rep("A", 10),
rep("B", 10),
rep("A", 10),
rep("B", 10),
rep("A", 10),
rep("B", 10),
rep("A", 10),
rep("B", 10)))
我想将其绘制为小提琴图,与窄箱形图对齐并按“类型”分组:
ggplot(data = df, aes(x = groups, y = value, fill = type)) +
geom_violin()+
geom_boxplot(width = 0.1, outlier.colour = NA)
但是,箱线图与小提琴图不一致。告诉 ggplot 做这样的覆盖缺少什么论据?
谢谢!