簡體   English   中英

使用R在同一圖上的一個經驗CDF上疊加多理論CDF

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

我有一個觀察到的樣本,該樣本已建模為7種不同的分布。 我想在一個圖中顯示經驗分布函數(Ecdf)和擬合的Ecdf,以便在不帶顏色的日記帳中發布時可以識別該圖。 當我們允許使用顏色時,我也很想看到答案。 可以從數據下載中下載數據

我使用了以下代碼,我想對其進行修改,以使其在黑白打印中更具區別。

#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)  

我認為您只需要上面的內容,但要用黑白兩種顏色,在這種情況下, 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