Patric
Patric

Reputation: 53

How to plot a graph of Probability density function using ggplot

Here is my data set

link to dataset

I want to plot a graph showing the Probability density function for the variable quality of the division on the type of wine.

I try this:

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

but it plot flat line.

ok, i think my code don't have any sens. I want to do somethink lie that: Example x-quality of wines(dry,semi-dry....)

What can I do?

Upvotes: 3

Views: 19150

Answers (1)

Michele
Michele

Reputation: 8763

Is this what you want?

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

EDIT:

I see your point, but probably you just need to rescale the y values (am I correct?) so is not this what you're after? changed the image

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

enter image description here

or all in one with different fill

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

enter image description here

Upvotes: 10

Related Questions