mk_cdfplot: Create a function for making publishable ggplot2 CDF plots.

View source: R/mk_cdfplot.R

mk_cdfplotR Documentation

Create a function for making publishable ggplot2 CDF plots.

Description

mk_cdfplot takes a data frame as input and returns a function for plotting empirical cumulative distribution function (ECDF) or its complement (CCDF) of a continuous variable from the data frame.

Usage

mk_cdfplot(df)

Arguments

df

A data frame.

Value

function(xvar, colorby = "1", complement = FALSE, linew = 0.7, add_vline_median = FALSE, show_label_median = add_vline_median, legend_title = colorby, legend_pos = "right", font_size = 14)

  • xvar. String, name of a continuous variable for x-axis.

  • colorby. String, name of a categorical variable for grouping x. For each group, a CDF curve will be drawn with a different color. Default = "1", indicating no such variable is supplied.

  • complement. Logical (default = FALSE), if TRUE, produce a function for plotting the complement of CDF.

  • linew. Number, width of the line. Default = 0.7.

  • add_vline_median. Logical (default = FALSE), if TRUE, add vertical dashed line segments at the median values going up and touching the CDF curves. To make it easy to look at, also add horizontal dashed line at y=0.5. Only effective when 'complement = FALSE'.

  • show_label_median. Logical (default is the same as the value of 'add_vline_median'), if TRUE, show median values along the vertical median lines. Otherwise, don't show. Only effective when 'complement = FALSE'.

  • legend_title. String, legend title. Default is the name of the colorby variable.

  • legend_pos. String, legend position. Default = "right".

  • font_size. Overall font size. Default = 14. The font size of the axes and legend text is a fraction of this value.

  • .... Optional parameters for 'stat_ecfd()'. For example, instead of using the default ‘geom = ’step'‘, you can set 'geom = ’point'', which will draw the ecdf in dots instead of stepped line segments. For another example, instead of using the default 'pad = TRUE', you can set 'pad = FALSE' to stop the ecdf curve at its boundaries given by the data instead of extending it to +Inf and -Inf horizontally.

Examples

inst/examples/ex-mk_cdfplot.R

gmlang/ezplot documentation built on Sept. 18, 2022, 6:33 a.m.