0

I have an observed sample which has been modeled with 7 different distributions. 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. 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)  
Hamid
  • 1
  • 1
  • Not sure what the yn...y7's are supposed to be. You may want to read [this](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – CrunchyTopping Jul 10 '19 at 19:23
  • Dear @Anomie I modified the post to make it clear. Thnaks. – Hamid Jul 10 '19 at 19:39

1 Answers1

0

I think you just want the above but in black and white, in which case ggplot2's theme_bw takes care of this.

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")
CrunchyTopping
  • 803
  • 7
  • 17
  • Dear @Anomie many thanks. First of all error in `[.data.frame`(data1, complete.cases(data1)) : undefined columns selected is appeared when running code. Three more question please. 1) Please introduce me a good introductory reference for learning the package ggplot 2) In produced figure is possible to replace "variable" at the top of legend area with "distributions" or it default. 3)if we would like to have survival function at y axis and the plot would appear in log-log scale how we can do it. – Hamid Jul 11 '19 at 06:53
  • See edits. http://www.cookbook-r.com/Graphs/ is great. I'm not sure about the 3rd question, you should do some sleuthing online or ask a new question if you can't find the answer. – CrunchyTopping Jul 11 '19 at 12:13