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
)
The data frame containing the variables to consider.
The x-variable to consider.
The y-variable to consider.
The time variable to consider.
The easing method, you can find more here <https://github.com/d3/d3-ease>. Defaults to 'Linear'.
The time spent paused on each frame (time point) in milliseconds.
The time spent transitioning between frames in milliseconds.
A D3 categorical color scheme, you can find more here <https://github.com/d3/d3-scale-chromatic#categorical>. Defaults to 'Accent'.
Whether to sort or not the bars. Takes three values 'none' which is the default, 'ascending' or 'descending'. Defaults to 'descending'.
The distance between each bar. The value goes from 0 to 0.99 included. Defaults to 0.1.
the font size of the x-axis labels. Defaults to 10.
the font size of the y-axis labels. Defaults to 10.
the number of y-axis ticks to consider. Defaults to 10.
Optional. The title of the x-axis.
The font size of the x-axis title. Defaults to 16.
Optional. The title of the y-axis.
The font size of the y-axis title. Defaults to 14.
Optional. The title of the plot.
The font size of the plot title. Defaults to 22.
The stroke color of the bars. Defaults to 'black'.
Optional. the stroke width of the bars.
The font family to consider for the titles. Defaults to "Verdana, Geneva, Tahoma, sans-serif".
The background color of the SVG. Defaults to "#CAD0D3" HEX color.
The background color of the panel. Defaults to "#EBEBEBFF" HEX color.
The color of the x-axis grid lines. Defaults to 'white'.
The color opacity of the bars (from 0 to 1). Defaults to 1.
Whether to show a label for the value of the time variable. Defaults to TRUE.
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.
Optional. The width of the SVG output.
Optional. The height of the SVG output.
An animated SVG bar chart race, wrapped in a div.
library(gapminder)
library(dplyr)
# let's select a set of countries only
gapminder <- gapminder %>%
filter(
country %in% c("Algeria", "Mexico", "Iceland", "Greece", "Finland")
)
barChartRace(
data = gapminder,
x = "lifeExp",
y = "country",
time = "year",
ytitle = "Country",
xtitle = "Life expectancy",
title = "Bar chart race of countries life expectancy"
)