3

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?

8
  • how can I get the data set? it seems to be an image. Edit and add, dput(wines) Commented Jun 2, 2013 at 12:02
  • I don't understand. You want output of dput(wines)? Commented Jun 2, 2013 at 12:31
  • The link you put it's perfect thanks. I thought the data frame was not so big, so dput was feasible... Commented Jun 2, 2013 at 12:32
  • 1
    It plots a horizontal line because all db values are zero. Try a different distribution. Commented Jun 2, 2013 at 12:46
  • 2
    Also - a beta with parameters 1 and 1 will give a uniform distribution so if anything you should have been expecting a flat line as the outcome... Commented Jun 2, 2013 at 13:43

1 Answer 1

10

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

Sign up to request clarification or add additional context in comments.

5 Comments

oh, i want to plot a graph showing Probability density function, somehow i miss one word in my post. I very sorry for that.
in fact it is what i'm looking for, but i want do it for every kind of wines(dry,semi-dry....)
@user1972123 now it should be fine. And if you want to remove the "sweet" level from the first image just remove the single row there is in the data frame for sweetness=="sweet" and it'll plot only three charts
Wait - this is what the data looks like? I don't think a density plot is the best thing to be making when you want to visualize data that takes only a small number of integer values...
@Dason possibly... e.g. in this specific case I would have used a bar chart. Just because in my "environment" it would be seen as more professional... and easier to be understood by senior managers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.