组合盒小提琴图未对齐
Combined box-violin plot not aligned
我想使用带有箱线图的小提琴图绘制二维分布图。结果可能真的很吸引人,但前提是做得对。
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)
然而这是我得到的:
箱线图沿着属于该因素的轴对齐。我怎样才能将它们移动到小提琴图的中心?
这里有这个问题的答案:
how to align violin plots with boxplots
您可以使用位置参数根据需要移动图形元素:
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")
我想使用带有箱线图的小提琴图绘制二维分布图。结果可能真的很吸引人,但前提是做得对。
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)
然而这是我得到的:
箱线图沿着属于该因素的轴对齐。我怎样才能将它们移动到小提琴图的中心?
这里有这个问题的答案: how to align violin plots with boxplots
您可以使用位置参数根据需要移动图形元素:
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")