1
votes

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

1 Answers

1
votes

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)