简体   繁体   English

使用R在同一图上的一个经验CDF上叠加多理论CDF

[英]Multi theoretical CDFs ovelay on one empirical CDF in the same plot using R

I have an observed sample which has been modeled with 7 different distributions. 我有一个观察到的样本,该样本已建模为7种不同的分布。 I would like to show the empirical distribution function (Ecdf) and the fitted Ecdf's in one plot, for the case that this plot should be recognizable for publishing in a not colored journal. 我想在一个图中显示经验分布函数(Ecdf)和拟合的Ecdf,以便在不带颜色的日记帐中发布时可以识别该图。 I am also interested to see the answer when we are allowed to use colors. 当我们允许使用颜色时,我也很想看到答案。 Data can be downloaded from Data Download 可以从数据下载中下载数据

I have used the following codes, which I would like to modify them in order to make it more distinguishable in black-white print. 我使用了以下代码,我想对其进行修改,以使其在黑白打印中更具区别。

#plot x vs F(x)
fun.ecdf <- ecdf(my.obs1)
my.ecdf <- fun.ecdf(sort(my.obs1))
plot(sort(my.obs1),my.ecdf,type="l",lwd=3,xlab="x=area",ylab="F(x)")
lines(sort(my.obs1),y1,lty=2,lwd=2,col=116)
lines(sort(my.obs1),y2,lty=3,lwd=2,col=142)
lines(sort(my.obs1),y3,lty=4,lwd=2,col=96)
lines(sort(my.obs1),y4,lty=5,lwd=2,col=504)
lines(sort(my.obs1),y5,lty=6,lwd=2,col=259)
lines(sort(my.obs1),y6,lty=7,lwd=2,col=373)
lines(sort(my.obs1),y7,lty=8,lwd=2,col=370)
legend(45,0.85, legend = c("empirical distribution","dist A", 
"distB","distC","distD","distE","distF","distG"),
col="black",116,142,96,504,259,373,370),
lty = 1:8, cex = 0.8)  

I think you just want the above but in black and white, in which case ggplot2 's theme_bw takes care of this. 我认为您只需要上面的内容,但要用黑白两种颜色,在这种情况下, ggplot2theme_bw会解决这个问题。

library(ggplot2)
library(reshape)
library(plotly)
data1<-data1[complete.cases(data1),]
data1$my.obs1<-sort(data1$my.obs1)
fun.ecdf <- ecdf(data1$my.obs1)
data1<-
data1%>%
  mutate(.,'empirical distribution'=fun.ecdf(sort(my.obs1)))%>%
  melt(.,id.vars="my.obs1")
ggplot(data1,aes(x=my.obs1,y=value,linetype=variable))+geom_line( size = 1)+theme_bw()+
  theme(legend.position=c(1,1), legend.justification=c(1.3,1.4),
        panel.border = element_rect(colour = "black", fill=NA),
        legend.box.background = element_rect(colour = "black"),
        legend.background = element_blank())+
 labs(linetype="distributions")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM