| multiBarChart {Rnvd3} | R Documentation | 
Multibar chart
Description
HTMLwidget displaying a multibar chart.
Usage
multiBarChart(
  data,
  formula,
  by,
  palette = "viridis",
  xAxisTitle = NULL,
  yAxisTitle = NULL,
  margins = list(b = 100, l = 70),
  duration = 1300,
  rotateLabels = 0,
  groupSpacing = 0.1,
  xAxisTitleDistance = 35,
  yAxisTitleDistance = -5,
  yAxisShowMaxMin = FALSE,
  yAxisTickFormat = ".0f",
  xLabelsFontSize = "1rem",
  yLabelsFontSize = "1rem",
  rightAlignYaxis = FALSE,
  reduceXticks = FALSE,
  staggerLabels = FALSE,
  wrapLabels = FALSE,
  useInteractiveGuideline = FALSE,
  tooltipFormatters = list(value = NULL, header = NULL, key = NULL),
  tooltipTransitions = TRUE,
  tooltipShadow = TRUE,
  radioButtonMode = FALSE,
  legendTitle = NULL,
  legendHjust = -20,
  width = "100%",
  height = NULL,
  elementId = NULL
)
Arguments
| data | dataframe used for the chart | 
| formula | a two-sided formula like  | 
| by | string, the "by" variable; must be a column name of  | 
| palette | this can be either the name of a viridis color palette, e.g.
 | 
| xAxisTitle | a title for the x-axis; if  | 
| yAxisTitle | a title for the y-axis; if  | 
| margins | a named list defining the margins, with names  | 
| duration | duration of the transition, a number of milliseconds | 
| rotateLabels | a number, the angle of rotation of the labels of the x-axis (in degrees) | 
| 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 | 
| 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 | 
| rightAlignYaxis | Boolean, whether to put the y-axis on the right side instead of the left | 
| reduceXticks | Boolean, whether to reduce the ticks on the x-axis so that the x-labels are less likely to overlap | 
| staggerLabels | Boolean, whether to make the x-labels stagger at different distances from the axis so they're less likely to overlap | 
| wrapLabels | Boolean, whether to split long x-labels by new lines in order to prevent overlapping | 
| useInteractiveGuideline | Boolean, other kind of tooltips: sets the chart to use a guideline and floating tooltip instead of requiring the user to hover over specific hotspots | 
| tooltipFormatters | formatters for the tooltip; each formatter must
be  
 | 
| tooltipTransitions | Boolean, whether to style the tooltip with a fade effect | 
| tooltipShadow | Boolean, whether to style the tooltip with a shadow | 
| radioButtonMode | Boolean, whether to authorize only one selection in
the legend (i.e. only one level of the ' | 
| legendTitle | a title for the legend, or  | 
| legendHjust | horizontal adjustment of the legend title | 
| 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.
Note
In Shiny, you can style the axis titles with the help of CSS; see the
shiny example. It is also possible outside of Shiny;
see the second example below, where we set the CSS with the help of
prependContent.
Examples
library(Rnvd3)
# in this example we use the tooltip formatters for styling only; we could
# achieve the same result with the help of CSS
dat <- reshape2::melt(
  apply(HairEyeColor, c(1, 2), sum), value.name = "Count"
)
multiBarChart(
  dat, Count ~ Eye, "Hair",
  tooltipFormatters = list(
    value = JS(
      "function(x){",
      "  return '<span style=\"color:red;\">' + x + '</span>';",
      "}"
    ),
    header = JS(
      "function(x){",
      "  return '<span style=\"color:green;\">' + x + '</span>';",
      "}"
    ),
    key = JS(
      "function(x){",
      "  return '<i style=\"color:blue;\">' + x + '</i>';",
      "}"
    )
  )
)
# style axis titles with CSS ####
library(htmltools)
CSS <- HTML(
  ".nvd3 .nv-axis.nv-x text.nv-axislabel,
   .nvd3 .nv-axis.nv-y text.nv-axislabel {
     font-size: 2rem;
     fill: red;
  }"
)
widget <- multiBarChart(
  dat, Count ~ Eye, "Hair", palette = "turbo"
)
prependContent(
  widget,
  tags$style(CSS)
)