Question: How to create multiple density plots in one
0
gravatar for biostarsb
23 months ago by
biostarsb20
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 http://www.statmethods.net/graphs/images/density3.png) 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 • 1.2k views
ADD COMMENTlink modified 23 months ago • written 23 months ago by biostarsb20

btw the link is not opening any image.

if you are using ggplot2

library(ggplot2)
x <- data.frame(v1=rnorm(100),v2=rnorm(100,1,1),v3=rnorm(100,0,2))
library(ggplot2)
library(reshape2)
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 23 months ago • written 23 months ago by ivivek_ngs4.7k

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

ADD REPLYlink written 4 weeks ago by a.b.federico0

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

ADD REPLYlink written 4 weeks ago by ivivek_ngs4.7k
Please log in to add an answer.

Help
Access

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