【问题标题】:Overlay plots in RR中的叠加图
【发布时间】:2013-01-29 11:44:00
【问题描述】:

我想根据来自数据框不同列的值在一个图表中一起绘制 3 个条形图。

它应该看起来像something like this

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

有人可以帮帮我吗?

【问题讨论】:

  • 链接重定向,如果您无法上传,请将其保存到图片托管并发布该链接
  • 请提供一个可重复的例子来说明你已经做过的事情......
  • 在地块之间尝试par(new=TRUE) ...
  • 使用ylim 强制公共轴限制和axes=FALSE 关闭轴的重叠绘图(可能?axis 添加自定义轴)
  • ggplot2 包允许做你想做的事。

标签: r


【解决方案1】:

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

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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-23
    • 1970-01-01
    • 1970-01-01
    • 2018-01-06
    • 2022-07-14
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多