map-stacked-bar-chart: Stacked Bar Chart.

Description Usage Arguments Value Warning Examples

Description

stacked_bar_chart creates a stacked bar chart using the specified library, which can be used in the library's %>% workflow. Data must be provided in long format.

hc_stacked_bar_chart should not be used directly, it generates a stacked barchart using Plotly.

plotly_stacked_bar_chart should not be used directly, it generates a stacked barchart using Plotly.

Usage

1
2
3
4
5
6
7
stacked_bar_chart(data, library = "highcharter", categories.column,
  categories.order = NA, subcategories.column, value.column,
  stacking.type = NA, subcategories.order = NA, return.data = FALSE)

hc_stacked_bar_chart(...)

plotly_stacked_bar_chart(...)

Arguments

data

A dataframe, must be long-formatted.

library

Which library to use, highchart is default.

categories.column

Column containing the bar groupings (or categories), in a horizontally orientated barchart these will be the y-axis labels. Must be given as formula, i.e. ~country

categories.order

Order for categories to appear in the bar chart, a character vector containing as many unique categories as there ar in data. For data_stacked_bar_chart the order might be c("United Kingdom", "Canada", "China", "Estonia", "Egypt", "France", "Germany", "Ireland", "Saudi Arabia", "Slovakia"). Default to NA, the categories order will be determined by their appearance in data.

subcategories.column

Column containing different measures, i.e sub-categorisations. Must be given as formula, i.e. ~country

value.column

Column containing bar values, i.e. lengths. Must be given as formula, i.e. ~country

stacking.type

Stacking to apply to bars, default NULL. Possible values, c("percent", "normal")

subcategories.order

Order for sub-categories, note for plotly the legend is ordered correctly but bars are reverse ordered

return.data

Useful tool for debugging libraries that perform internal data wrangling, for instance highcharter. If TRUE the function will return the restructured data provided to the htmlwidget generating the output. Default to FALSE.

...

all arguments provided to stacked_bar_chart.

Value

Stacked bar chart of the class specified by the specified library.

Warning

These should be considered utility functions only, the magic is contained within the htmlwidget library, it is perfectly possible breaking changes to the library and/or the underling JavaScript library will break these. In such case, refer to http://ox-it.github.io/OxfordIDN_htmlwidgets for generic tutorials on the widely used htmlwidget libraries and how to select an alternative visualisation library.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## Not run: 
## Generate a stacked bar chart using highcharter
stacked_bar_chart(data = data_stacked_bar_chart,
library = "highcharter",
categories.column = ~country,
subcategories.column = ~activity,
value.column = ~hours)

## Generate a staced bar chart with bars stacked such that the subcategories totals within a
## category sum to 100%, using plotly.
activity_order <- c("Unclassified", "Business", "Overlay", "Personal", "Teleconference")
country_order <- c("Canada", "China", "Egypt", "Estonia", "France", "Germany", "Ireland",
"Saudi Arabia", "Slovakia", "United Kingdom")
stacked_bar_chart(data = data_stacked_bar_chart,
               library = "plotly",
               categories.column = ~country,
               categories.order = country_order,
               subcategories.column = ~activity,
               value.column = ~hours,
               subcategories.order = activity_order,
               stacking.type = "percent")

## End(Not run)

ox-it/oidnChaRts documentation built on May 24, 2019, 5:55 p.m.