plot_bars: Plot bars of numerical variables

Description Usage Arguments Examples

View source: R/plot_bars.R

Description

This function creates nicely formatted, standardized bar-plots.

Usage

1
2
3
4
5
6
7
plot_bars(df, x, y = NULL, y_prop = FALSE, x_type = "num",
  fill = NULL, facet = NULL, binwidth = NULL, position = "stack",
  stat = "count", fct_order = FALSE, angle = 0, title = TRUE,
  subtitle = NULL, caption = NULL, lab_x = "Value range",
  lab_y = "Proportion", legend = TRUE, vline = c(NaN), alpha = 0.7,
  quantile_low = 0, quantile_high = 1, theme_type = "ipsum",
  palette = "awtools")

Arguments

df

A data frame.

x

A numeric/ categorical variable to plot the bar plot.

y

A numeric variable which contains summarised y values (before plotting). Use only with stat = "identity".

y_prop

A logical variable to choose between counts/ proportion on the y axis. Defaults to FALSE (proportion).

x_type

Character identifier for type of the variable x defined above: "num" for numeric (plots histogram) and "char" for character (plots bar chart). Defauls to "num".

fill

Select an additional grouping variable to be used for plotting. Defaults to NULL.

facet

Select an additional faceting variable to create facets. Defaults to NULL.

binwidth

Select binwidth, defaults to NULL and lets ggplot select the optimal binwidth.

position

Select the position of the barplot from: "stack" (default), "dodge" or "fill".

stat

Character identifier for whether the data is already grouped ("identity") or if the function needs to aggregate data at the level of x ("count").

fct_order

Should the factors be reordered by their frequency? Defaults to FALSE.

angle

Select the rotation angle for the x axis labels. Defaults to 0.

title

Should the plot title appear automatically. Defaults to TRUE.

subtitle

Text that is displayed on the subtitle. Defaults to NULL.

caption

Text that is displayed on the caption. Defaults to NULL.

lab_x

Text that is displayed on the x axis. Defaults to "Level".

lab_y

Text that is displayed on the y axis. Defaults to "Value range".

legend

Should the plot legend appear automatically. Defaults to TRUE.

vline

Should any horizontal lines be added to the plot. Defaults to c(NaN).

alpha

Select plot fill transparency. Defaults to 0.7.

quantile_low

Select lower percentile for outliers exclusion. Defaults to 0.0%.

quantile_high

Select upper percentile for outliers exclusion. Defaults to 1.0%.

theme_type

Select a theme type from themes available in the apply_theme function. Defaults to "ipsum".

palette

Select a palette type with the select_palette function. Defaults to "awtools".

Examples

1
2
3
4
5
library(tidyverse)

diamonds_sum <- diamonds %>%
  group_by(cut) %>%
  summarise(mean_carat = mean(carat, na.rm = TRUE))

konradsemsch/ggrapid documentation built on Nov. 4, 2019, 3:56 p.m.