2

目前我正在写我的学士论文,我所有的情节都是用 ggplot2 创建的。现在我需要两个 ecdfs 的图,但我的问题是两个数据帧的长度不同。但是通过添加值来均衡长度,我会改变分布,因此我的第一个想法是不可能的。但是禁止使用具有不同长度的两个不同数据帧的 ecdf 图。

daten <- peptidPSMotherExplained[peptidPSMotherExplained$V3!=-1,]
daten <- cbind ( daten , "scoreDistance"= daten$V2-daten$V3 )    
daten2 <- peptidPSMotherExplained2[peptidPSMotherExplained2$V3!=-1,]
daten2 <- cbind ( daten2 , "scoreDistance"= daten2$V2-daten2$V3 )
p <- ggplot(daten, aes(x = scoreDistance)) + stat_ecdf()
p <- p + geom_point(aes(x = daten2$lengthDistance))
p

使用 R 的正常绘图功能,它是可能的

plot(ecdf(daten$scoreDistance))
plot(ecdf(daten2$scoreDistance),add=TRUE)

但它看起来与我所有的其他情节不同,我不喜欢这个。

有没有人为我解决?

谢谢你,托比亚斯


例子:

df <-data.frame(scoreDifference = rnorm(10,0,12))
df2 <- data.frame(scoreDifference = rnorm(5,-3,9)) 
plot(ecdf(df$scoreDifference))
plot(ecdf(df2$scoreDifference),add=TRUE)

那么如何在ggplot中实现这种情节呢?

4

2 回答 2

1

我不知道应该使用什么几何图形来绘制这样的图,但是对于组合两个数据集,您可以简单地在新图层中指定数据,

ggplot(df, aes(x = scoreDifference)) + 
  stat_ecdf(geom = "point") + 
  stat_ecdf(data=df2, geom = "point") 
于 2013-05-21T13:48:01.073 回答
0

我认为,以正确的方式重塑你的数据可能会让 ggplot2 为你工作:

df <-data.frame(scoreDiff1 = rnorm(10,0,12))
df2 <- data.frame(scoreDiff2 = rnorm(5,-3,9))
library('reshape2')
data <- merge(melt(df),melt(df2),all=TRUE)

然后,data在正确的形状下,您可以简单地继续用颜色(或形状,或任何您想要的)绘制内容以区分两个数据集:

p <- ggplot(daten, aes(x = value, colour = variable)) + stat_ecdf()

希望这就是你要找的东西!?

于 2013-05-21T14:11:04.943 回答