【问题标题】:Multiple Column Plots in ggplot2 that are nearly identicalggplot2 中的多列图几乎相同
【发布时间】:2013-03-18 16:19:54
【问题描述】:

我有一个看起来像这样的 .tsv 文件

MODEL           CA_RMSD BB_RMSD ALL_ATOM s1      s2     s3   
101_res_input   2.89    2.89    3.17    -84.37  -46.77  0.81   
102_res_input   3.29    3.29    3.52    -85.21  -50.49  1.04
103_res_input   3.74    3.73    3.98    -90.93  -48.18  1.65
104_res_input   3.09    3.07    3.34    -92.16  -49.63  1.03
105_res_input   3.44    3.43    3.69    -89.92  -49.81  1.08

我想要的是一张有 CA_RMSD 与 s1 的图表,然后是另一个有 CA_RMSD 与 s2 的图表,以及另一个有 CA_RMSD 与 s3 的图表,依此类推。散点图可能是我想象的最好的。我是 ggplot2 的新手,但似乎我想要使用刻面,因为我希望同一图像上的所有图,但是对于每个图,y 轴需要采用不同的比例。

对于每个图,我可以得到一个规模上的线性回归,告诉我哪些数据集相关性最好?必须有一些我缺少的功能才能做到这一点。

J

【问题讨论】:

  • 得到这些数据后,你基本上什么都没做?如果没有,那为什么不发布你到目前为止所拥有的?
  • 是的,我使用 qplot 单独绘制每一个,然后使用 mutliplot 将它们全部放在同一页面上。它非常低效且无法编写脚本。
  • 那么,最好把你的代码贴出来,直到你做了什么,然后问你不能做什么。否则,你会因为缺乏努力而被否决。

标签: r statistics ggplot2


【解决方案1】:

这个怎么样?

require(ggplot2)
require(reshape2)
df.m <- melt(df, id.var = "CA_RMSD", measure.var = c("X.s1", "s2", "s3"))
p <- ggplot(data = df.m, aes(x = CA_RMSD, y = value)) + 
    geom_point() + 
geom_smooth(method = "lm") + 
    facet_wrap(~ variable, nrow=1, scales="free")
cors <- ddply(df.m, .(variable), summarise, cor = round(cor(CA_RMSD, value), 2))
p + geom_text(data=cors, aes(label=paste("r=", cor, sep=""), 
                   x=c(3,3,3), y=c(-75, -50, 0)))

【讨论】:

  • 谢谢。我保证我会调查你描述的每个功能,这样我们就不必再看到这个问题了:)
猜你喜欢
  • 2011-12-27
  • 2020-11-04
  • 1970-01-01
  • 2014-01-20
  • 2018-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
相关资源
最近更新 更多