作为示例,这里是基于
diamonds
的堆叠密度图。一个简单的表格表明“公平”切工应该相当不常见,“理想”切工最常见,等等......,但是五种切工似乎在堆积图表上占据了或多或少相等的面积/比例。这让我很惊讶。
这可能是我的一个概念上的误解,我将不胜感激有人提供帮助。那么,堆积密度到底说明了什么?
library(tidyverse)
library(patchwork)
p1 <- diamonds %>%
ggplot() +
geom_density(aes(x = price, fill = cut), position = "stack")
p2 <- diamonds %>%
ggplot() +
geom_density(aes(x = price, fill = cut), position = "fill")
p1 / p2 + plot_layout(guides = "collect")
table(diamonds$cut)
#>
#> Fair Good Very Good Premium Ideal
#> 1610 4906 12082 13791 21551
创建于 2023 年 11 月 12 日,使用 reprex v2.0.2
密度在组合之前正在标准化。如果您不想这样,请使用
after_stat(count)
,例如
library(tidyverse)
diamonds %>%
ggplot() +
geom_density(aes(x = price, after_stat(count), fill = cut), position = "stack")
创建于 2023 年 11 月 12 日,使用 reprex v2.0.2