簡體   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