plotgg_stacked_columns: Plot columns as stacked bars

Description Usage Arguments Value Examples

View source: R/plotgg_stacked_columns.r

Description

Takes a data frame or tibble with one row per observation and multiple variables (columns) per observation. It then plots the selected variables as stacked bars per observation, possibly faceting the plot.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
plotgg_stacked_columns(
  dat,
  x,
  columns = NULL,
  facet_formula = NULL,
  gather_key = "key",
  gather_value = "value",
  custom_theme = ggplot2::theme(panel.background = ggplot2::element_blank(), panel.grid
    = ggplot2::element_blank(), axis.text = ggplot2::element_text(color = "black"),
    axis.title = ggplot2::element_text(color = "black", face = "bold"),
    axis.line.x.bottom = ggplot2::element_line(), axis.line.y.left =
    ggplot2::element_line())
)

Arguments

dat

A data frame or tibble with one row per observation and multiple variables (i.e. columns) per observations.

x

The name of the column to be used as an observation name. It will be used to as a label in the x axis of the plot.

columns

A character vector containing the names of the columns to stack. If NULL, all columns except for the column indicated by 'x' and the columns in 'facet_formula' will be included.

facet_formula

A formula to be used by facet_grid. It will split the stacked bars into panels.

gather_key

The key name to be used by gather. It will indicate the name for the gathered columns. The text itself will be used as the legend title.

gather_value

The value name to be used by gather. It will indicate the sum of values in the stacked bars. The text itself will be used as the y-axis title.

custom_theme

The result of a call to theme. It allows for control over the plot format

Value

A ggplot2 plot.

Examples

1
2
3
4
5
6
7
d <- tibble::tibble(sample = letters[1:4],
                    g1 = 4:1,
                    g2 = 1:4,
                    group = rep(LETTERS[1:2], 2))
plotgg_stacked_columns(d,
                       x = 'sample',
                       facet_formula = ~ group)

surh/HMVAR documentation built on Aug. 18, 2021, 1:21 a.m.