-4

I have three empirical distribution functions and I would like to plot these into one graph for an overview. The x label should say 'Bedienzeit (s) and I would like different colors and a legend. Unfortunately all I am trying, does not really work well.

Could anyone of you tell me how to do this?

Thanks a lot!!

Daten <- read_excel("Input/Daten_ohne_Anton_Leonie.xlsx")
G_40_TmK_Alle_VP <- Daten$G_40_TmK
G_40_BmK_Alle_VP <- Daten$G_40_BmK
G_40_WoK_Alle_VP <- Daten$G_40_WoK

#ECDF TmK
G_40_TmK_Alle_VP_ECDF <- ecdf(G_40_TmK_Alle_VP)

#ECDF BmK
G_40_BmK_Alle_VP_ECDF <- ecdf(G_40_BmK_Alle_VP)

#ECDF WoK
G_40_WoK_Alle_VP_ECDF <- ecdf(G_40_WoK_Alle_VP)
  • 4
    Welcome to Stack Overflow! Please take the [tour](https://stackoverflow.com/tour) and read through the [help center](http://stackoverflow.com/help), in particular [how to ask](https://stackoverflow.com/help/how-to-ask). Your best bet here is to do your research, search for related topics on SO, and give it a go. After doing more research and searching, post a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) of your attempt and say specifically where you're stuck, which can help you get better answers. – help-info.de May 06 '19 at 09:11
  • 1
    Not sure if this will work as you didn't provide a sample of your data. ```par(mfrow=c(3,1)) plot(G_40_TmK_Alle_VP_ECDF, xlab="Bedienzei", main="need_data_sample") plot(G_40_BmK_Alle_VP_ECDF, xlab="Bedienzei", main="need_data_sample") plot(G_40_WoK_Alle_VP_ECDF, xlab="Bedienzei", main="need_data_sample")``` – Paul Endymion May 06 '19 at 09:29

1 Answers1

1

Here is a starting point for you :

plot(ecdf(1:10), col = 1, xlab = "Bedienzeit (s)")
plot(ecdf(rep(1:2, 5)), add = TRUE, col = 2)
plot(ecdf(rep(1:5, 2)), add = TRUE, col = 3)
legend(8, 0.3, legend = paste("Série", 1:3), col = 1:3, lty = 1)

add = TRUE allows to plot several series.

Clemsang
  • 5,053
  • 3
  • 23
  • 41
  • Thank you so much! Is there a way to specify that the legend says TmK, BmK and WoK instead of Series 1, Series 2, Series 3? – Annsophie May 06 '19 at 10:48
  • @Annsophie yes replace the argument legend `paste("Serie", 1:3)` by your vector of names – Clemsang May 06 '19 at 11:50
  • Thanks a lot! :) – Annsophie May 06 '19 at 13:52
  • One more question - sorry :) do you know how to create a line instead of these steps? type = "l" doesnt work somehow:plot(G_40_TmK_Alle_VP_ECDF,verticals=TRUE, do.points=FALSE, xlab ='Bedienzeit in s', ylab = '', main = 'Empirische Verteilungsfunktionen (ECDF) bei 40 Grad\n Gesamte Stichprobe ', col = 3) lines(G_40_BmK_Alle_VP_ECDF,verticals=TRUE, do.points=FALSE, col = 2) lines(G_40_WoK_Alle_VP_ECDF,verticals=TRUE, do.points=FALSE, col = 4) legend(15, 0.8, legend = c("TmK", "BmK", "WoK"), col = c(3,2,4), lty = 1) – Annsophie May 07 '19 at 08:30
  • Plot is achieved with `plot.ecdf`. `ecdf(x)` is a function. Here is a trick to do what you want : `plot(1:10, ecdf(1:10)(1:10), type = "l")` – Clemsang May 07 '19 at 08:52