Shape Customization

To change the shape of the ECDF plot we use the geom parameter of the stat_ecdf() function. We can add any shape as the value of parameter geom. In this example, we have a stair-shaped ECDF plot made using stat_ecdf() function with the geom parameter being “step”.

R




# set seed
set.seed(1234)
 
# create a random data frame
sample_data <- data.frame(x = round(rnorm(20, mean=800, sd=450)))
 
# load library ggplot2
library(ggplot2)
 
# Basic ECDF plot using ggplot package
ggplot(sample_data, aes(x)) +
 
# stat_ecdf() function is used to plot ECDF plot
# geom parameter is used to shape plot as step
stat_ecdf(geom="step")


Output:

How to Make ECDF Plot with ggplot2 in R?

Empirical Cumulative Distribution Function Plot (ECDF) helps us to visualize one or more distributions. ECDF plot is a great alternative for histograms and it has the ability to show the full range of data without the need for various parameters.

In this article, we will discuss how to draw an ECDF plot using the ggplot2 package of R Programming language. To draw an ECDF plot, we use the stat_ecdf() function of the ggplot2 package of R Language.

Syntax: ggplot( df, aes(x)) + stat_ecdf( geom, col )

Parameters: 

  • df : determines dataframe used to plot ECDF plot
  • geom: determines the shape of plot, i.e., point, step,etc.
  • col: determines the color of plot

Similar Reads

Create a basic ECDF plot

In this example, we will create a basic ECDF plot. We will use the ggplot() function and the stat_ecdf() function to plot the ECDF plot....

Color Customization

...

Shape Customization

To change the color of the ECDF plot we use the col parameter of the stat_ecdf() function. We can add any color as the value of parameter col. We can even use hex codes of color. In this example, we have a green-colored ECDF plot made using stat_ecdf() function with the col parameter being green....

Multiple ECDF colored by group:

...

Contact Us