Ker*_*Ber 4 r data-visualization ggplot2
我将在这里使用小提琴图作为示例,但问题扩展到许多其他ggplot类型.
我知道如何通过一个因子沿x轴对我的数据进行子集化:
ggplot(iris, aes(x = Species, y = Sepal.Length)) +
geom_violin() +
geom_point(position = "jitter")
Run Code Online (Sandbox Code Playgroud)
而且我知道如何只绘制完整的数据集:
ggplot(iris, aes(x = 1, y = Sepal.Length)) +
geom_violin() +
geom_point(position = "jitter")
Run Code Online (Sandbox Code Playgroud)
我的问题是:有没有办法在同一个图中并排绘制完整数据和逐个因子?换句话说,对于虹膜数据,我可以制作一个沿x轴同时具有"完整数据"和"setosa"的小提琴曲线吗?
这样可以比较完整数据集的分布和该数据集的子集.如果这是不可能的,那么任何有关更好的可视化方法的建议也会受到欢迎:)
谢谢你的任何想法!
使用:
ggplot(iris, aes(x = "All", y = Sepal.Length)) +
geom_violin() +
geom_point(aes(color="All"), position = "jitter") +
geom_violin(data=iris, aes(x = Species, y = Sepal.Length)) +
geom_point(data=iris, aes(x = Species, y = Sepal.Length, color = Species),
position = "jitter") +
scale_color_manual(values = c("black","#F8766D","#00BA38","#619CFF")) +
theme_minimal(base_size = 16) +
theme(axis.title.x = element_blank(), legend.title = element_blank())
Run Code Online (Sandbox Code Playgroud)
得到: