2

I am trying to plot the CDF using ggplot2 in R and I get the following plotenter image description here

But the min and max values of the data are 1947 and 2017. I do not want the line to be plot beyond the ranges [1947, 2017].

ggplot(df, aes(x=year)) + stat_ecdf(geom="line") + xlab("Year") + xlim(1947, 2017)

Can anyone help with this issue?

Dinesh
  • 2,194
  • 3
  • 30
  • 52
  • Have you tried `xlim(1947,2017)` or something similar? – joran Apr 29 '18 at 01:38
  • i tried it but it gives me the same result - I updated the code above – Dinesh Apr 29 '18 at 01:40
  • Ok, you probably want the `expand` argument in `scale_x_continuous` then. Start with setting it to `c(0,0)` and then tinker until you get what you want. – joran Apr 29 '18 at 01:44

1 Answers1

5

Try using the pad parameter with FALSE value:

ggplot( data.frame(x=1947:2017), aes(x=x)) + stat_ecdf(geom="line", pad=FALSE)

enter image description here

IRTFM
  • 258,963
  • 21
  • 364
  • 487