Question: Plot multiple R empricial distributions with different X axis on the same plot
gravatar for maxime.policarpo
5 weeks ago by
France, Paris
maxime.policarpo80 wrote:


I am facing a problem on which i have to plot three empirical distributions in R with the function "ecdf" but one limitation is that those distributions don't have the same X-axis values.

For example I have three vectors :

vector1 <- c(-5,-10,-5,-9,-7,-9,-6,-4,-1,-3,-6,-8,-7,-5,-5,-4,-6,-8,-9)
vector2 <- c(11,12,45,74,12,122,141,52,54,69,87,54,52,48,96)
vector3 <- c(0.2,0.3,0.3,0.3,0.5,0.9,0.5,0.4,0.6,0.8,0.5,0.6)

I would like to plot the empirical distributions of those three vectors in the same graph (The Y-axis will stay the same, between 0 and 1) but with different X-axis (here, axis x1 will be between -10 and -1 while axis x3 will be between 0 and 1). I have found many questions regarding plotting different curves with different y-axis but never found how to do it with distributions and different X.

Would you have any idea ?

plot distribution R • 96 views
ADD COMMENTlink modified 5 weeks ago by RamRS23k • written 5 weeks ago by maxime.policarpo80

Please use the formatting bar (especially the code option) to present your post better. You can use backticks for inline code (`text` becomes text), or select a chunk of text and use the highlighted button to format it as a code block. I've done it for you this time.

ADD REPLYlink written 5 weeks ago by RamRS23k
gravatar for Corentin
5 weeks ago by
Corentin380 wrote:


You can use the lines() function, this allows you to add lines to an existing plot.

Do not forget to specify the x limits in your call to "plot()", in your example it would look like this:

plot(ecdf(vector1), xlim = c(-10, 141))
lines(ecdf(vector2), col = "blue")
lines(ecdf(vector3), col = "red")
ADD COMMENTlink written 5 weeks ago by Corentin380


Thanks for your answer, but this will create an unique x-axis for all my vectors. I think I will go this way because creating three different X-axis in the same graph dosn't seem very feasible :/

Have a good day,


ADD REPLYlink written 5 weeks ago by maxime.policarpo80

Another solution would be to use par(mfrow=c(1,3) to create three subplots in the same figure (see

If I understood correctly, what you want to achieve is to "cut" your x-axis where you do not have data, I would personally advise against it as it would be misleading.

ADD REPLYlink written 4 weeks ago by Corentin380
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1590 users visited in the last hour