ggplot 中的位置堆栈与身份之间有什么区别?

What is the difference between position stack vs identity in ggplot?

谁能解释一下 geom_density 位置选项 stackidentity。地块看起来非常不同,但仍然重叠。两者有什么根本区别?

由于某些原因,geom_density 帮助中没有解释。但是 position="stack" 像这样堆叠值:

position="identity" 像这样覆盖它们:

这是生成这些代码的代码:

n <- 1000
A <- data.frame(id='A',x=rnorm(n, 5, 2))
B <- data.frame(id='B',x=rexp(n, 1/4))
C <- data.frame(id='C',x=rexp(n, 1/8))
D <- data.frame(id='D',x=rexp(n, 1/16))
df <- rbind(A,B,C,D)

colorset = c('B'='red','A'='green','D'='black','C'='blue'  )

ggplot(df, aes(x)) +
  geom_density(aes(fill = id), alpha = .4, adjust = 2,position="stack") +
  scale_fill_manual(values=colorset) +
  scale_x_continuous( limits =c(0,40)) + labs(title="geom_density: position=`Stack`")

ggplot(df, aes(x)) +
  geom_density(aes(fill = id), alpha = .4, adjust = 2,position="identity") +
  scale_fill_manual(values=colorset) +
  scale_x_continuous( limits =c(0,40)) + labs(title="geom_density: position=`identity`")