简体   繁体   中英

ggplot: density plot error

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!!

Try this

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

在此处输入图片说明

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM