首页 文章

如何使用ggplot绘制概率密度函数图

提问于
浏览
-2

这是我的数据集

link to dataset

我想绘制一个图表,显示葡萄酒类型的可变品质的概率密度函数 .

我试试这个:

library(ggplot2)
db <- dbeta(wines$quality, 1, 1)
qplot(wines$quality, db, geom="line")

但它的情节平坦 .

好吧,我认为我的代码没有任何感觉 . 我想做一些想法:Example x-品质的葡萄酒(干,半干....)

我能做什么?

1 回答

  • 5

    这是你想要的吗?

    ggplot(wines) + geom_density(aes(quality))
    

    编辑:

    我明白了你的意思,但可能你只需要重新调整y值(我是否正确?)所以这不是你想要的吗? changed the image

    ggplot(wines[-4381,]) + geom_density(aes(x=quality)) +
      facet_wrap(~sweetnes)
    

    enter image description here

    或者所有在一个不同的 fill

    ggplot(wines) + geom_density(aes(x=quality, fill=sweetnes))
    

    enter image description here

相关问题