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

标签 r ggplot2 density-plot

关闭。这个问题需要details or clarity .它目前不接受答案。












想改善这个问题吗?通过 editing this post 添加详细信息并澄清问题.

4年前关闭。




Improve this question




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

最佳答案

出于某种原因,它没有在 geom_density 中解释。帮助。然而position="stack"像这样堆叠值:

enter image description here

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

enter image description here

这是生成这些的代码:

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`")

关于r - ggplot中的位置堆栈与身份之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44033592/

相关文章:

将数据框中所有高于 100 的值替换为相对于 100 的值,即 120 到 80

r - 将 `sample sizes` 添加到 ggplot violinplot 图例时出现问题

r - 在 R 中使用 ggplot 填充行之间的区域

r - 向 geom_密度_ridges 添加平均值

python - 在 python 中创建垂直线的密度图

mysql - R docker : Can't connect to local MySQL server through socket

r - 使用 glmer 提取随机效应分量的标准偏差

r - 以径向格式显示集群

r - 如何在 R 和 ggplot2 中的背景图像上拟合绘图

r - ggplot_stat_密度2d 生态分布图