【问题标题】:Combined box-violin plot not aligned [duplicate]组合箱小提琴图未对齐[重复]
【发布时间】:2015-11-06 20:37:49
【问题描述】:

我想使用带有箱线图的小提琴图绘制二维分布图。结果可能非常令人着迷,但前提是做得正确。

ToothGrowth$dose <- as.factor(ToothGrowth$dose)
head(ToothGrowth)
plot <- ggplot(ToothGrowth, aes(x=dose, y=len, fill=supp)) +
  geom_violin() + geom_boxplot(width=0.1)  + theme(legend.position="none")
ggsave(filename="Violinboxplot.png", plot, height=6, width=4)

这就是我得到的:

箱线图沿属于因子的轴对齐。如何将它们移动到小提琴图的中心?

【问题讨论】:

    标签: r ggplot2 boxplot violin-plot


    【解决方案1】:

    这里有这个问题的答案: how to align violin plots with boxplots

    您可以根据需要使用 position 参数来移动图形元素:

    dodge <- position_dodge(width = 0.5)
    
    ggplot(ToothGrowth, aes(x=dose, y=len, fill=supp)) +
      geom_violin(position = dodge) +
      geom_boxplot(width=.1, position = dodge) +
      theme(legend.position="none")
    

    【讨论】:

      猜你喜欢
      • 2015-01-16
      • 2019-10-09
      • 2018-01-15
      • 1970-01-01
      • 2021-05-01
      • 2022-12-09
      • 1970-01-01
      • 2021-05-13
      • 2016-07-02
      相关资源
      最近更新 更多