ggplot2 ECDF plot : Quick start guide for Empirical Cumulative Density Function - R software and data visualization

This R tutorial describes how to create an ECDF plot (or Empirical Cumulative Density Function) using R software and ggplot2 package. ECDF reports for any given number the percent of individuals that are below that threshold.

The function stat_ecdf() can be used.

Create some data

df <- data.frame(height = round(rnorm(200, mean=60, sd=15)))
##   height
## 1     42
## 2     64
## 3     76
## 4     25
## 5     66
## 6     68

ECDF plots

ggplot(df, aes(height)) + stat_ecdf(geom = "point")
ggplot(df, aes(height)) + stat_ecdf(geom = "step")

For any value, say, height = 50, you can see that about 25% of our individuals are shorter than 50 inches

Customized ECDF plots

# Basic ECDF plot
ggplot(df, aes(height)) + stat_ecdf(geom = "step")+
labs(title="Empirical Cumulative \n Density Function",
     y = "F(height)", x="Height in inch")+


This analysis has been performed using R software (ver. 3.2.4) and ggplot2 (ver. 2.1.0)

Enjoyed this article? I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Twitter, Facebook or Linked In.

Show me some love with the like buttons below... Thank you and please don't forget to share and comment below!!
Avez vous aimé cet article? Je vous serais très reconnaissant si vous aidiez à sa diffusion en l'envoyant par courriel à un ami ou en le partageant sur Twitter, Facebook ou Linked In.

Montrez-moi un peu d'amour avec les like ci-dessous ... Merci et n'oubliez pas, s'il vous plaît, de partager et de commenter ci-dessous!

This page has been seen 14452 times