histogram.dt: Histogram as data.table

View source: R/class-plotdata-histogram.R

histogram.dtR Documentation

Histogram as data.table

Description

This function returns a data.table of plot-ready data with one row per group (per panel). Columns 'x' and 'y' contain the bin label and count respectively. Column 'group' and 'panel' specify the group the series data belongs to. It is possible to plot missingness in the stratification variables as an explicit 'No data' value using 'evilMode'.

Usage

histogram.dt(
  data,
  variables,
  binWidth = NULL,
  value = c("count", "proportion"),
  binReportValue = c("binWidth", "numBins"),
  barmode = c("stack", "overlay"),
  viewport = NULL,
  overlayValues = NULL,
  sampleSizes = c(TRUE, FALSE),
  completeCases = c(TRUE, FALSE),
  evilMode = c("noVariables", "allVariables", "strataVariables"),
  verbose = c(TRUE, FALSE)
)

Arguments

data

data.frame to make plot-ready data for

variables

veupathUtils::VariableMetadataList

binWidth

numeric value indicating width of bins, character (ex: 'year') if xaxis is a date

value

String indicating how to calculate y-values ('count, 'proportion')

binReportValue

String indicating if number of bins or bin width used should be returned

barmode

String indicating if bars should be stacked or overlaid ('stack', 'overlay')

viewport

List of min and max values to consider as the range of data

overlayValues

veupathUtils::BinList providing overlay values of interest

sampleSizes

boolean indicating if sample sizes should be computed

completeCases

boolean indicating if complete cases should be computed

evilMode

String indicating how evil this plot is ('strataVariables', 'allVariables', 'noVariables')

verbose

boolean indicating if timed logging is desired

Value

data.table plot-ready data

Evil Mode

An 'evilMode' exists. It will do the following:
- when ‘strataVariables' it will return ’no data' as a regular value for strata vars but will discard such cases for the axes vars.
- when ‘allVariables' it will return ’no data' as a regular value for all variables.
- when 'noVariables' it will do the sensible thing and return complete cases only.
- not return statsTables
- allow smoothed means and agg values etc over axes values where we have no data for the strata vars
- return a total count of plotted incomplete cases
- represent missingness poorly, conflate the stories of completeness and missingness, mislead you and steal your soul

Examples

# Construct example data
df <- data.table('entity.xvar' = rnorm(100),
                 'entity.overlay' = sample(c('red','green','blue'), 100, replace=T), stringsAsFactors = F)

# Create VariableMetadataList that specifies variable role in the plot and supplies variable metadata
variables <- veupathUtils::VariableMetadataList(
  veupathUtils::VariableMetadata(
    variableClass = veupathUtils::VariableClass(value = 'native'),
    variableSpec = veupathUtils::VariableSpec(variableId = 'xvar', entityId = 'entity'),
    plotReference = veupathUtils::PlotReference(value = 'xAxis'),
    dataType = veupathUtils::DataType(value = 'STRING'),
    dataShape = veupathUtils::DataShape(value = 'CATEGORICAL')
  ),
  veupathUtils::VariableMetadata(
    variableClass = veupathUtils::VariableClass(value = 'native'),
    variableSpec = veupathUtils::VariableSpec(variableId = 'overlay', entityId = 'entity'),
    plotReference = veupathUtils::PlotReference(value = 'overlay'),
    dataType = veupathUtils::DataType(value = 'STRING'),
    dataShape = veupathUtils::DataShape(value = 'CATEGORICAL')
  )
)

viewport <- list('xMin'=min(df$xvar), 'xMax'=max(df$xvar))

# Returns a data table with plot-ready data
dt <- histogram.dt(df, map, binWidth=0.3, value='count', barmode='stack', viewport=viewport)

VEuPathDB/plot.data documentation built on Feb. 20, 2025, 6:33 p.m.