Skip to contents

Create a stacked bar chart of digit distribution, with a grouping variable on the x axis, and the distribution of digits in a particular digit place on the y axis.

Usage

plotDigitCounts(
  dfDigits,
  colGroup,
  colPlace,
  strGroupLabel = colGroup,
  strPlaceLabel = colPlace,
  strChartTitle =
    glue::glue("Digit Distribution for {strPlaceLabel} of Data by {strGroupLabel}"),
  scaleDigitPalette = ggplot2::scale_fill_brewer(palette = "Set3"),
  themePlot = ggplot2::theme_bw()
)

Arguments

dfDigits

data.frame A data.frame with a grouping column and at least one column for a digit place.

colGroup

character The name of a column to group by.

colPlace

character The name of a column with integer values between 0 and 9.

strGroupLabel

character An optional name to use for the grouping column in labels.

strPlaceLabel

character An optional name to use for the place column in labels.

strChartTitle

character An optional title for the chart.

scaleDigitPalette

An optional ggplot2::scale_fill_discrete() palette to use for the digits.

themePlot

An optional ggplot2::theme() to apply to the plot.

Examples

sample_data <- data.frame(
  siteID = sample(c("siteA", "siteB", "siteC"), 1000, replace = TRUE),
  onesPlace = sample(0:9, 1000, replace = TRUE)
)
plotDigitCounts(sample_data, "siteID", "onesPlace")

plotDigitCounts(sample_data, "siteID", "onesPlace", "Site", "One Place")

plotDigitCounts(sample_data, "siteID", "onesPlace", scaleDigitPalette = NULL)