bar_chart: Function for plotting beautiful barcharts in ggplot

Description Usage Arguments Details Examples

View source: R/bar-chart.R

Description

Function for plotting beautiful barcharts in ggplot

Usage

1
2
3
4
bar_chart(data, y, x, na.rm = FALSE, title = NULL, sub.title = NULL,
  flip = FALSE, y.title = NULL, x.title = NULL, decreasing = NULL,
  bar.colour.name = NULL, y.lim = NULL, y.breaks = NULL,
  bar.width = NULL, ...)

Arguments

data

data frame containing data for plotting

y

character string specifying column name in data that should be y variable

x

character string specifying column name in data that should be x variable

na.rm

a logical indicating whether NA values should be stripped before the computation proceeds

title

character string specifying chart title

sub.title

character string specifying chart sub title

flip

logical indicating whether barchart should be flipped or not

y.title

character string specifying y-axis title

x.title

character string specifying x-axis title

decreasing

logical indicating whether y values should be ordered and in which direction

bar.colour.name

character string indicating which bars to be coloured based on x names (see details)

y.lim

numeric vector with length two providing y-axis limits (min and max)

y.breaks

numeric vector specifying where ticks appear

Details

The option bar.colour.name allows for multiple bars based on x-axis names to get a different colour. If set to NULL all bars will have same default colour. Since ggplot2 version 2.2.0 this has changed as the ordering gets complicated when y values contain both positive and negative values. As a result bar colouring is only allowed decreasing is set to TRUE.

Examples

1
2
3
4
5
6
data(mtcars)
mtcars$name <- rownames(mtcars)
bar_chart(mtcars, "mpg", "name", flip = TRUE,
title = "Miles per gallon across different car models",
scale.y = c(0, 40, 5),
decreasing = TRUE)

pgarnry/ggplotHelper documentation built on May 25, 2019, 2:54 a.m.