How to create multiple density plots in one
0
0
Entering edit mode
7.6 years ago
biostarsb ▴ 30

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 • 6.7k views
ADD COMMENT
0
Entering edit mode

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 REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 1952 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6