在R中叠加绘图

4
我想在一张图中绘制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")

有人能帮我一下吗?


1
请提供一个可重现的示例,说明您已经做了什么... - Paul Hiemstra
1
尝试在绘图之间添加 par(new=TRUE)... - Ben Bolker
2
使用 ylim 强制共同的坐标轴限制,使用 axes=FALSE 关闭轴的重叠绘制(可能需要使用 ?axis 添加自定义轴)。 - Ben Bolker
@ BenBolker:谢谢!您的建议完美地解决了问题。 - user1987607
3
ggplot2软件包可以实现您想要的功能。 - crow16384
显示剩余2条评论
1个回答

0

我不确定这是否是您想要的...但根据您发送的图形,我认为这将有所帮助:

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)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接