Not understanding the behavior of ..density

前端 未结 1 751
被撕碎了的回忆
被撕碎了的回忆 2020-12-21 11:14

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

1条回答
  •  一向
    一向 (楼主)
    2020-12-21 11:33

    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..)) 
    

    0 讨论(0)
提交回复
热议问题