hMultiBarChart: Horizontal multibar chart

Description Usage Arguments Value Examples

View source: R/rnvd3.R

Description

HTMLwidget displaying a horizontal multibar chart.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
hMultiBarChart(
  data,
  formula,
  by,
  palette = "viridis",
  xAxisTitle = NULL,
  yAxisTitle = NULL,
  margins = list(b = 100, l = 100),
  duration = 1300,
  groupSpacing = 0.1,
  xAxisTitleDistance = 25,
  yAxisTitleDistance = -5,
  yAxisShowMaxMin = FALSE,
  yAxisTickFormat = ".0f",
  nticks = 5,
  xLabelsFontSize = "1rem",
  yLabelsFontSize = "1rem",
  showValues = FALSE,
  tooltipFormatters = list(value = NULL, header = NULL, key = NULL),
  tooltipTransitions = TRUE,
  tooltipShadow = TRUE,
  width = "100%",
  height = NULL,
  elementId = NULL
)

Arguments

data

dataframe containing the data used for the chart

formula

a two-sided formula like y ~ x, where "x" and "y" are two column names of data

by

string, the "by" variable; must be a column name of data

palette

this can be either the name of a viridis color palette, e.g. "viridis", "cividis" or "turbo" (see viridis), or a vector of colors, or a function that takes an integer argument (the required number of colors) and returns a character vector of colors (e.g. you can use colorRampPalette)

xAxisTitle

a title for the x-axis; if NULL, the title is taken from the formula argument

yAxisTitle

a title for the y-axis; if NULL, the title is taken from the formula argument

margins

a named list defining the margins, with names "t", "r", "b" and "l", for "top", "right", "bottom" and "left" respectively; you can specify only certain margins in the list to change just those parts

duration

duration of the transition, a number of milliseconds

groupSpacing

a number, controls the distance between groups of bars

xAxisTitleDistance

a number, controls the distance between the x-axis and its title

yAxisTitleDistance

a number, controls the distance between the y-axis and its title

yAxisShowMaxMin

Boolean, whether to show the min and the max on the y-axis

yAxisTickFormat

a d3 formatting string for the y-axis; see d3.format

nticks

integer, the number of ticks on the y-axis

xLabelsFontSize

a CSS measure, the font size of the labels on the x-axis

yLabelsFontSize

a CSS measure, the font size of the labels on the y-axis

showValues

Boolean, whether to show the values next to the bars

tooltipFormatters

formatters for the tooltip; each formatter must be NULL for the default formatting, otherwise a JavaScript function created with JS; there are three possible formatters (see the example):

value

formatter for the y-value displayed in the tooltip

header

formatter for the tooltip header (this is the x-value)

key

formatter for the value of the 'by' variable

tooltipTransitions

Boolean, whether to style the tooltip with a fade effect

tooltipShadow

Boolean, whether to style the tooltip with a shadow

width

width of the chart container, must be a valid CSS measure

height

height of the chart container, must be a valid CSS measure

elementId

an id for the chart container; commonly useless

Value

A htmlwidget displaying a grouped/stacked bar chart.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
library(Rnvd3)
dat <- aggregate(breaks ~ wool + tension, data = warpbreaks, mean)
levels(dat[["tension"]]) <- c("Low", "Medium", "High")

hMultiBarChart(
  dat, breaks ~ wool, "tension", yAxisShowMaxMin = TRUE,
  yAxisTitle = "Mean of breaks", yAxisTickFormat = ".01f"
)

# the axis titles are small, let's make them bigger
library(htmltools)
CSS <- HTML(
  ".nvd3 .nv-axis.nv-x text.nv-axislabel,
   .nvd3 .nv-axis.nv-y text.nv-axislabel {
     font-size: 1rem;
  }"
)
prependContent(
  hMultiBarChart(
    dat, breaks ~ wool, "tension", yAxisShowMaxMin = TRUE,
    yAxisTitle = "Mean of breaks", yAxisTickFormat = ".01f"
  ),
  tags$style(CSS)
)

Rnvd3 documentation built on Sept. 5, 2021, 5:18 p.m.