不理解..density的行为 [英] Not understanding the behavior of ..density
本文介绍了不理解..density的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面的数据框中,我预计密度的y轴值为0.6和0.4,但它们是1.0。我觉得显然有一些非常基本的东西,我错过了我正在使用的方式......密度......但脑冻结。我将如何使用..density获得所需的行为。任何帮助将不胜感激。
df < - data.frame (a = c(是,否,是,是,否))
m < - ggplot(df,aes(x = a))
m + geom_histogram (aes(y = ..density ..))
谢谢,
--JT
解决方案
按照@ Arun的评论:
目前,是
和 no
属于不同的群组。为了使它们成为同一组的一部分,设置了分组美学:
m < - ggplot(df,aes(x = a ,group = 1))#'group = 1'将所有x的组设置为1
m + geom_histogram(aes(y = ..density ..))
In the dataframe below, I would expect the y axis values for density be 0.6 and 0.4, yet they are 1.0. I feel there is obviously something extremely basic that I am missing about the way I am using ..density.. but am brain freezing. How would I obtain the desired behavior using ..density.. Any help would be appreciated.
df <- data.frame(a = c("yes","no","yes","yes","no"))
m <- ggplot(df, aes(x = a))
m + geom_histogram(aes(y = ..density..))
Thanks, --JT
解决方案
As per @Arun's comment:
At the moment, yes
and no
belong to different groups. To make them part of the same group set a grouping aesthetic:
m <- ggplot(df, aes(x = a , group = 1)) # 'group = 1' sets the group of all x to 1
m + geom_histogram(aes(y = ..density..))
这篇关于不理解..density的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文