繁体   English   中英

R中的叠加图

[英]Overlay plots in R

我想基于数据框的不同列的值在一个图中绘制3个条形图。

看起来应该是这样的

曲线1的y值是曲线2和3的y值的总和。曲线1和2的颜色可以完全填充(例如蓝色和红色),但曲线3的颜色必须是半透明的。

我能够使用barplot()函数分别为每个列创建一个绘图,但我无法将它们组合在一个图形中。

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")

有人可以帮我一把吗?

我不确定这是不是你想要的......但根据你发送的图片,我认为这会有所帮助:

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM