0

I am using this code to generate the empirical cumulative distribution function for the two samples (you can put any numerical values in them). I would like to put them in the same plot but if you run the following commands everything is overlapping really bad [see picture 1]. Is there any way to do it like this [see picture 2] (also I want the symbols to disappear and be a line like the picture 2) .

plot(ecdf(sample[,1]),pch = 1)
par(new=TRUE)        
plot(ecdf(sample[,2]),pch = 2)

picture 1:https://www.dropbox.com/s/sg1fr8jydsch4xp/vanboeren2.png?dl=0

picture 2:https://www.dropbox.com/s/erhgla34y5bxa58/vanboeren1.png?dl=0

Update: I am doing this

  df1 <- data.frame(x = sample[,1]) 
  df2 <- data.frame(x = sample[,2])   
  ggplot(df1, aes(x, colour = "g")) + stat_ecdf()
  +geom_step(data = df2) 
  scale_x_continuous(limits = c(0, 5000)) `

which is very close (in terms of shape) but still can not put them at the same plot.

  • you have to set the same limits to the x axis for both plots. See if [this](http://stackoverflow.com/questions/42517471/my-parabola-shifts-along-the-x-axis-as-i-change-x-lim/42517775#42517775) helps. – R. Schifini Apr 19 '17 at 16:33
  • thanks for your reply. How ? – giorgos kapetanidis Apr 19 '17 at 16:34
  • [Here](http://stackoverflow.com/questions/3606697/how-to-set-limits-for-axes-in-ggplot2-r-plots) is one answer that may help – R. Schifini Apr 19 '17 at 16:35
  • still can not do it :) if you can be more specific please. Just copy paste what I have written in the update section and show me please :) – giorgos kapetanidis Apr 19 '17 at 16:38
  • If your question is about how to plot multiple datasets in the same plot with `ggplot`, see [here](http://stackoverflow.com/questions/9109156/ggplot-combining-two-plots-from-different-data-frames) – aosmith Apr 19 '17 at 16:46
  • I still can not do it, can you please find the mistake? df1 <- data.frame(x = sample[,1]) df2 <- data.frame(x = sample[,2]) ggplot(df1, aes(x, colour = "g")) + stat_ecdf()+geom_step(data = df2) scale_x_continuous(limits = c(0, 5000)) – giorgos kapetanidis Apr 19 '17 at 16:51

1 Answers1

0

Try this with basic plot:

df1 <- data.frame(x = runif(200,1,5)) 
df2 <- data.frame(x = runif(200,3,8))

plot(ecdf(df1[,1]),pch = 1, xlim=c(0,10), main=NULL)
par(new=TRUE)        
plot(ecdf(df2[,1]),pch = 2, xlim=c(0,10), main=NULL)

Both graphs have now the same xlim (try removing it to see both superimposed incorrectly). The main=NULL removes the title

Result:

enter image description here

R. Schifini
  • 9,085
  • 2
  • 26
  • 32