Create a bar chart race.

barChartRace(
  data,
  x,
  y,
  time,
  ease = "Linear",
  frameDur = 500,
  transitionDur = 500,
  colorCategory = "Accent",
  sort = "descending",
  paddingWidth = 0.1,
  xFontSize = 10,
  yFontSize = 10,
  xticks = 10,
  xtitle = NULL,
  xtitleFontSize = 16,
  ytitle = NULL,
  ytitleFontSize = 14,
  title = NULL,
  titleFontSize = 22,
  stroke = "black",
  strokeWidth = NULL,
  font = "Verdana, Geneva, Tahoma, sans-serif",
  bgcol = "#CAD0D3",
  panelcol = "#EBEBEBFF",
  xgridlinecol = "white",
  opacity = 1,
  timeLabel = TRUE,
  timeLabelOpts = list(size = 32, prefix = "", suffix = "", xOffset = 0.5, yOffset = 1),
  width = NULL,
  height = NULL
)

Arguments

data

The data frame containing the variables to consider.

x

The x-variable to consider.

y

The y-variable to consider.

time

The time variable to consider.

ease

The easing method, you can find more here <https://github.com/d3/d3-ease>. Defaults to 'Linear'.

frameDur

The time spent paused on each frame (time point) in milliseconds.

transitionDur

The time spent transitioning between frames in milliseconds.

colorCategory

A D3 categorical color scheme, you can find more here <https://github.com/d3/d3-scale-chromatic#categorical>. Defaults to 'Accent'.

sort

Whether to sort or not the bars. Takes three values 'none' which is the default, 'ascending' or 'descending'. Defaults to 'descending'.

paddingWidth

The distance between each bar. The value goes from 0 to 0.99 included. Defaults to 0.1.

xFontSize

the font size of the x-axis labels. Defaults to 10.

yFontSize

the font size of the y-axis labels. Defaults to 10.

xticks

the number of y-axis ticks to consider. Defaults to 10.

xtitle

Optional. The title of the x-axis.

xtitleFontSize

The font size of the x-axis title. Defaults to 16.

ytitle

Optional. The title of the y-axis.

ytitleFontSize

The font size of the y-axis title. Defaults to 14.

title

Optional. The title of the plot.

titleFontSize

The font size of the plot title. Defaults to 22.

stroke

The stroke color of the bars. Defaults to 'black'.

strokeWidth

Optional. the stroke width of the bars.

font

The font family to consider for the titles. Defaults to "Verdana, Geneva, Tahoma, sans-serif".

bgcol

The background color of the SVG. Defaults to "#CAD0D3" HEX color.

panelcol

The background color of the panel. Defaults to "#EBEBEBFF" HEX color.

xgridlinecol

The color of the x-axis grid lines. Defaults to 'white'.

opacity

The color opacity of the bars (from 0 to 1). Defaults to 1.

timeLabel

Whether to show a label for the value of the time variable. Defaults to TRUE.

timeLabelOpts

Options for labeling the value of the time variable. Takes a list specifying the `size`, `prefix`, `suffix`, `xOffset`, and `yOffset`. Offsets are scaled relative to the dimensions of the label, from the bottom-right corner of the panel.

width

Optional. The width of the SVG output.

height

Optional. The height of the SVG output.

Value

An animated SVG bar chart race, wrapped in a div.

Examples

data <- data.frame( pop = c(57,66,76,88,101,114,129,143,156, 169,180,190,69,71,74,76,79,78,78,78,81,82,82,82,86, 92,96,101,107,114,118,122,124,126,127,127,30,35, 41,48,56,64,72,80,88,96,102,109,22,26,30,35,41, 47,53,60,67,75,83,91,26,29,34,39,45,51,56,63,70, 76,81,85), year = c(1952L,1957L,1962L,1967L,1972L,1977L, 1982L,1987L,1992L,1997L,2002L,2007L,1952L,1957L,1962L, 1967L,1972L,1977L,1982L,1987L,1992L,1997L,2002L,2007L, 1952L,1957L,1962L,1967L,1972L,1977L,1982L,1987L,1992L, 1997L,2002L,2007L,1952L,1957L,1962L,1967L,1972L,1977L, 1982L,1987L,1992L,1997L,2002L,2007L,1952L,1957L,1962L, 1967L,1972L,1977L,1982L,1987L,1992L,1997L,2002L,2007L, 1952L,1957L,1962L,1967L,1972L,1977L,1982L,1987L,1992L, 1997L,2002L,2007L), country = as.factor(c("Brazil","Brazil", "Brazil","Brazil","Brazil","Brazil","Brazil", "Brazil","Brazil","Brazil","Brazil","Brazil","Germany", "Germany","Germany","Germany","Germany", "Germany","Germany","Germany","Germany","Germany", "Germany","Germany","Japan","Japan","Japan","Japan", "Japan","Japan","Japan","Japan","Japan","Japan", "Japan","Japan","Mexico","Mexico","Mexico", "Mexico","Mexico","Mexico","Mexico","Mexico", "Mexico","Mexico","Mexico","Mexico","Philippines", "Philippines","Philippines","Philippines","Philippines", "Philippines","Philippines","Philippines", "Philippines","Philippines","Philippines","Philippines", "Vietnam","Vietnam","Vietnam","Vietnam", "Vietnam","Vietnam","Vietnam","Vietnam","Vietnam", "Vietnam","Vietnam","Vietnam")) ) barChartRace( data = data, x = "pop", y = "country", time = "year", ytitle = "Country", xtitle = "Population (in millions)", title = "Bar chart race of country populations" )