2

I am trying to plot some density plots overlaid on each other using ggplot

ggplot(den2, aes(x = V1,y=V2, fill = lines)) + geom_density()

However I'm getting this error: Error in if (nrow(layer_data) == 0) return() : argument is of length zero

Can someone tell me whats going wrong? Data den2 can be found here: https://drive.google.com/file/d/0ByW0yQz1oPLZNV93UVlrSXF0X28/view?usp=sharing

Thanks!!

1
  • This post looks like it has some useful information for you. As the answerer said, the key point is that a density plot is a univariate thing, so you do it for one variable at a time (but possibly with grouping). Commented Jul 26, 2015 at 20:57

1 Answer 1

1

Try this

ggplot(den2, aes(x=V1, y=V2, fill=factor(lines))) + geom_polygon(alpha=0.5)

enter image description here

For 1-D density plots, you just supply one variable, like you would to a histogram. So, you could do something like this instead,

ggplot(den2, aes(x=V1, fill=factor(lines))) + geom_density(alpha=0.5)
Sign up to request clarification or add additional context in comments.

Comments

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.