r - Plot barplot as density plot in ggplot -


could me plot data below density plot colour=variable?

> head(combined_length.m)   length                     seq           mir variable     value 1     22  tgaggtattaggttgtatggtt mmu-let-7c-5p     ago1  8.622468 2     23 tgagggagtaggttgtatggttt mmu-let-7c-5p     ago1 22.212471 3     21   tgaggtagtaggttgcatggt mmu-let-7c-5p     ago1  9.745199 4     22  tgaggtagtatgttgtatggtt mmu-let-7c-5p     ago1 11.635982 5     22  tgagttagtaggttgtatggtt mmu-let-7c-5p     ago1 13.203627 6     20    tgaggtagtaggctgtatgg mmu-let-7c-5p     ago1  7.752571  ggplot(combined_length.m, aes(factor(length),value)) + geom_bar(stat="identity") + facet_grid(~variable) +   theme_bw(base_size=16 

i tried without success:

ggplot(combined_length.m, aes(factor(length),value)) + geom_density(aes(fill=variable), size=2)  error in data.frame(counts = c(167, 9324, 177, 150451, 62640, 74557, 4,  :    arguments imply differing number of rows: 212, 6, 1, 4 

enter image description here

i want this:

http://i.stack.imgur.com/qitos.jpgenter image description here

using factor(length) x seems create problems. use length.

also, density plots display distribution of whatever define x. definition y axis density @ given value of x. in code seem trying specify both x , y, makes no sense. can specify y in geom_density(...) controls scaling, shown below. [note: example has 1 type of variable (ago1) created artificial dataset].

set.seed(1)   # reproducible example df <- data.frame(variable=rep(letters[1:3],c(5,10,15)),                  length  =rpois(30,25),                  value   =rnorm(30,mean=20,sd=5))  library(ggplot2) ggplot(df,aes(x=length))+geom_density(aes(color=variable)) 

in representation, area under each curve 1. same setting y=..density..

ggplot(df,aes(x=length))+geom_density(aes(color=variable,y=..density..)) 

you can set y=..count.. scales based on counts. in example, since there 15 observations c , 5 a, blue curve (c) has 3 times area red curve (a).

ggplot(df,aes(x=length))+geom_density(aes(color=variable,y=..count..)) 

you can set y=..scaled.. adjusts curves maximum value in each corresponds 1.

ggplot(df,aes(x=length))+geom_density(aes(color=variable,y=..scaled..)) 

finally, if want rid of annoying lines, use stat_density(...) instead:

ggplot(df,aes(x=length))+   stat_density(aes(color=variable),geom="line",position="identity") 


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -