Skip to content

plotCDF() creates a plot of the empirical cumulative distribution function for a numeric vector of continuous data. It is similar to ecdf() with some visual modifications.

plotCDFbyGroup() creates a plot with a series of cumulative distribution function (CDF) plots stratified/split by a grouping variable of (usually) meta data, e.g. Response grouping.

plotCDFlist() creates a series of cumulative distribution function (CDF) plots from a numeric list object.

Usage

plotCDF(
  x,
  col = soma_colors$purple,
  x.lab = "values",
  y.lab = bquote(~P(X < x)),
  main = "Empirical Cumulative Distribution Function",
  lty = "solid",
  add.gauss = FALSE
)

plotCDFbyGroup(
  data,
  apt,
  group.var,
  cols,
  xlim = NULL,
  x.lab = bquote(italic(log)[10] ~ (RFU)),
  main = apt,
  lty = "solid",
  ablines = NULL,
  include.counts = FALSE
)

plotCDFlist(.data, label = "Group", main = "CDF by Group", ...)

Arguments

x

A numeric vector.

col

Character. String for the color of the line.

x.lab

Character. Optional string for the x-axis. Otherwise one is automatically generated (default).

y.lab

Character. Optional string for the y-axis. Otherwise one is automatically generated (default).

main

Character. Main title for the plot. See ggtitle() for ggplot2 style graphics.

lty

Character. Passed to geom_vline(). See ggtitle().

add.gauss

Logical. Should a Gaussian fit of the data be plotted with the PDF?

data

A soma_adat or data.frame object containing RFU data.

apt

Character. The name of a column in data to use in generating CDFs. Typically an aptamer measurement.

group.var

An unquoted column name from data containing group labels.

cols

Character. A vector of colors for the groups/boxes. For plotDoubleHist(), must be length = 2.

xlim

Numeric. Limits for the x-axis. See coord_cartesian().

ablines

Numeric. A vector of x-axis position(s) for vertical lines to be added to the CDF or PDF.

include.counts

Logical. Should class counts be added to the plot legend?

.data

A named list of numeric vectors (or a data.frame) containing the data to plot.

label

Character. A label for the grouping variable, i.e. what the entries of the list represent.

...

Additional arguments passed to either plotCDFbyGroup() or plotPDFbyGroup(), primarily one of:

  • x.lab

  • lty

  • cols

  • xlim

  • fill

  • ablines

See also

stat_ecdf(), pnorm()

Other cdf-pdf-plots: plotPDF()

Author

Stu Field

Examples

# `plotCDF()`
x <- rnorm(100, mean = 5)
plotCDF(x)

plotCDF(x, col = "darkred")

plotCDF(x, col = "dodgerblue", add.gauss = TRUE)


# `plotCDFbyGroup()`
data  <- SomaDataIO::example_data |> dplyr::filter(SampleType == "Sample")
anno  <- SomaDataIO::getTargetNames(SomaDataIO::getAnalyteInfo(data))
fsh   <- "seq.3032.11"
title <- anno[[fsh]]
plotCDFbyGroup(log10(data), apt = fsh, group.var = Sex, main = title)

lines <- split(log10(data[[fsh]]), data$Sex) |>
  vapply(median, double(1))
plotCDFbyGroup(log10(data), apt = fsh, group.var = Sex,
               ablines = lines, main = title)

plotCDFbyGroup(log10(data), apt = fsh, group.var = Sex,
               include.counts = TRUE, main = title)


# `plotCDFlist()`
x <- withr::with_seed(101,
  mapply(mean = 3:5, n = c(10, 100, 1000), FUN = rnorm) |>
    setNames(paste0("Group", 1:3))
)
lengths(x)
#> Group1 Group2 Group3 
#>     10    100   1000 

sapply(x, mean)
#>   Group1   Group2   Group3 
#> 3.245040 3.964522 4.969620 

# warning: RFU values should all be positive!
plotCDFlist(x)

plotCDFlist(x, label = "SplitBy")

plotCDFlist(x, x.lab = "My x-axis", main = "Variable `x` CDF")

medians <- vapply(x, median, 0.0)
plotCDFlist(x, ablines = medians, main = "Variable `x` CDF")