Question: How to create multiple density plots in one
gravatar for biostarsb
2.6 years ago by
biostarsb20 wrote:

Hello everyone

I have a table of two columns

Category size mRNA 2000 mRNA 2300 mRNA 15000 siRNA 40 tRNA 120 siRNA 78 siRNA 38 mRNA 800

And I need to make a sensity plot (like here so that put the size in x and the desnity in Y

Is there a way to do this?

Ps: I used ggplot but I can not color that lines and leave the fill empty

Thank you in advance.

R • 2.4k views
ADD COMMENTlink modified 2.6 years ago • written 2.6 years ago by biostarsb20

btw the link is not opening any image.

if you are using ggplot2

x <- data.frame(v1=rnorm(100),v2=rnorm(100,1,1),v3=rnorm(100,0,2))
data<- melt(x)
ggplot(data,aes(x=value, fill=variable)) + geom_density(alpha=0.25)

If you are using just R base

plot (density(x$v1))
lines (density(x$v2))
lines (density(x$v3))

use the paramters for color and fill. if you want to fill.

Just to clarify it is not a bioinformatics question , probably an R plot or stackoverflow.

ADD REPLYlink modified 2.6 years ago • written 2.6 years ago by ivivek_ngs4.8k

Terrific answer. The reshape2 package is the key. Thank you!

ADD REPLYlink written 8 months ago by a.b.federico0

Indeed it is but sadly the OP did not acknowledge or upvote it. ;)

ADD REPLYlink written 8 months ago by ivivek_ngs4.8k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1639 users visited in the last hour