Charting in R

I want to build 3 rows in one plot based on values ​​from different columns of a data frame.

It should look something like this .

The y-values ​​of graph 1 are the sum of the values ​​of graphs 2 and 3. The color of section 1 and 2 can be completely filled (for example, blue and red), but the color of section 3 must be translucent.

I managed to make a graph for each column separately using the barplot() function, but I could not combine them into one graph.

 barplot(covpatient[[1]]$cov, names.arg = covpatient[[1]]$exon, xlab = covpatient[[1]]$gene[1] , ylab = "read depth" , border = "blue", col = "blue") barplot(covpatient[[1]]$plus, names.arg = covpatient[[1]]$exon, xlab = covpatient[[1]]$gene[1] , ylab = "read depth" , border = "red", col = "red") barplot(covpatient[[1]]$min, names.arg = covpatient[[1]]$exon, xlab = covpatient[[1]]$gene[1] , ylab = "read depth" , border = "gray", col = "gray") 

Can anyone give me a hand?

+4
source share
1 answer

I'm not quite sure if this is what you want ... but based on the graphic you sent, I think this will help:

 require(ggplot2) require(reshape2) covpatient <-list() covpatient$cov <-rnorm(100,2) covpatient$plus <-rnorm(100,4) covpatient$min <-rnorm(100,1) plot_covpatient <- do.call(rbind,covpatient) melted_plot_covpatient<-melt(plot_covpatient,value.name = 'Value') ggplot(melted_plot_covpatient,aes(group=Var1))+ geom_density(aes(Value,colour=Var1,fill=Var1),alpha=.5) 
0
source

All Articles