[英]Overlay plots in R
I want to plot 3 barplots together in one graph based on values from different columns of a data frame. 我想基于数据框的不同列的值在一个图中绘制3个条形图。
It should look something like this . 看起来应该是这样的 。
The y-values of plot 1 are the sum of the y-values of plot 2 and 3. The color of plot 1 and 2 can be fully filled (eg blue & red), but the color of plot 3 has to be translucent. 曲线1的y值是曲线2和3的y值的总和。曲线1和2的颜色可以完全填充(例如蓝色和红色),但曲线3的颜色必须是半透明的。
I was able to make a plot for each column separately using the barplot()
function, but I was not able to combine them in one graph. 我能够使用
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")
Could someone give me a hand? 有人可以帮我一把吗?
I'm not exactly sure if this is what you want... but based on the graphic that 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.