Title: | Create Interactive Chart with the JavaScript 'Billboard' Library |
---|---|
Description: | Provides an 'htmlwidgets' interface to 'billboard.js', a re-usable easy interface JavaScript chart library, based on D3 v4+. Chart types include line charts, scatterplots, bar/lollipop charts, histogram/density plots, pie/donut charts and gauge charts. All charts are interactive, and a proxy method is implemented to smoothly update a chart without rendering it again in 'shiny' apps. |
Authors: | Victor Perrier [aut, cre], Fanny Meyer [aut], NAVER Corp [cph] (billboard.js library), Mike Bostock [cph] (d3.format library) |
Maintainer: | Victor Perrier <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.5.0.9000 |
Built: | 2024-10-30 09:24:47 UTC |
Source: | https://github.com/dreamrs/billboarder |
htmlwidget
interface to the
billboard.js javascript chart libraryThis package allow you to use billboard.js (https://naver.github.io/billboard.js/), a re-usable easy interface JavaScript chart library, based on D3 v4+.
Victor Perrier (@dreamRs_fr)
Useful links:
Report bugs at https://github.com/dreamRs/billboarder/issues
Data are available in "long" and "wide" format.
avengers avengers_wide
avengers avengers_wide
A data frame with 24 rows and 4 variables:
Name of the hero
Power skill
Value (1-7)
Character description
An object of class data.frame
with 6 rows and 5 columns.
Marvel Wikia (https://marvel.fandom.com/wiki/Marvel_Database) and Chris Zhou (http://bl.ocks.org/chrisrzhou/2421ac6541b68c1680f8)
A gauge that automatically updates itself in Shiny apps.
bauge( value, min = 0, max = 100, colors = NULL, steps = NULL, label_tooltip = NULL, label_show = TRUE, label_format = NULL, label_extents = NULL, expand = TRUE, subtitle = NULL, full_circle = FALSE, gauge_width = NULL, width = NULL, height = NULL, elementId = NULL )
bauge( value, min = 0, max = 100, colors = NULL, steps = NULL, label_tooltip = NULL, label_show = TRUE, label_format = NULL, label_extents = NULL, expand = TRUE, subtitle = NULL, full_circle = FALSE, gauge_width = NULL, width = NULL, height = NULL, elementId = NULL )
value |
Value for the gauge. |
min |
Minimal value for the gauge, default to |
max |
Maximal value for the gauge, default to |
colors |
Vector of color(s), if more than one, |
steps |
Upper bound for changing colors. |
label_tooltip |
Label to appear on the tooltip, when mouse is hovering the gauge. |
label_show |
Show or not minimal and maximal labels. |
label_format |
JavaScript function to format inner label. |
label_extents |
JavaScript function to set custom labels. |
expand |
Enable or disable expanding gauge. |
subtitle |
Additional text to add below the value. |
full_circle |
Show full circle as donut. When set to |
gauge_width |
Set width of gauge chart. |
width |
Width of the element container. |
height |
Height of the element container. |
elementId |
Use an explicit element ID for the widget. |
bauge(45) bauge(67, colors = "#F6C600") bauge(90, full_circle = TRUE) bauge(90, max = 210, gauge_width = 20, label_format = suffix(" km/h")) # Shiny example if (interactive()) { library(shiny) ui <- fluidPage( baugeOutput(outputId = "gauge", width = "300px"), actionButton(inputId = "update_value", label = "Update value"), actionButton(inputId = "update_max", label = "Update max") ) server <- function(input, output, session) { value <- reactive({ input$update_value round(sample.int(100, 1)) }) max_value <- reactive({ input$update_max sample(100:200, 1) }) output$gauge <- renderBauge({ bauge( value = value(), max = max_value(), steps = c(30, 60, 90, 100), colors = c("#FF0000", "#F97600", "#F6C600", "#60B044") ) }) } shinyApp(ui, server) }
bauge(45) bauge(67, colors = "#F6C600") bauge(90, full_circle = TRUE) bauge(90, max = 210, gauge_width = 20, label_format = suffix(" km/h")) # Shiny example if (interactive()) { library(shiny) ui <- fluidPage( baugeOutput(outputId = "gauge", width = "300px"), actionButton(inputId = "update_value", label = "Update value"), actionButton(inputId = "update_max", label = "Update max") ) server <- function(input, output, session) { value <- reactive({ input$update_value round(sample.int(100, 1)) }) max_value <- reactive({ input$update_max sample(100:200, 1) }) output$gauge <- renderBauge({ bauge( value = value(), max = max_value(), steps = c(30, 60, 90, 100), colors = c("#FF0000", "#F97600", "#F6C600", "#60B044") ) }) } shinyApp(ui, server) }
Output and render functions for using bauge within Shiny applications and interactive Rmd documents.
baugeOutput(outputId, width = "100%", height = "200px") renderBauge(expr, env = parent.frame(), quoted = FALSE)
baugeOutput(outputId, width = "100%", height = "200px") renderBauge(expr, env = parent.frame(), quoted = FALSE)
outputId |
output variable to read from |
width , height
|
Must be a valid CSS unit (like |
expr |
An expression that generates a bauge |
env |
The environment in which to evaluate |
quoted |
Is |
Add custom style for regions and grid lines
bb_add_style( bb, region = NULL, x_grid = NULL, y_grid = NULL, ..., .list = NULL )
bb_add_style( bb, region = NULL, x_grid = NULL, y_grid = NULL, ..., .list = NULL )
bb |
A |
region |
A named list with style associated with region. |
x_grid |
A named list with style associated with grid line on the X-axis. |
y_grid |
A named list with style associated with grid line on the Y-axis. |
... , .list
|
Used internally. |
A billboard
htmlwidget
object.
# Change default color for regions billboarder() %>% bb_linechart(data = sin(seq(-pi, pi, length.out = 30))) %>% bb_regions( list(start = 0, end = 10, class = "custom"), # add custom class list(start = 19, end = 29, class = "foo") ) %>% bb_add_style(region = list(custom = "fill: red;", foo = "fill: #009246;")) # Customize grid line and text billboarder() %>% bb_linechart(data = sin(seq(-pi, pi, length.out = 30))) %>% bb_y_grid(lines = list(list( value = 0, text = "Zero", position = "middle", class = "zero" ))) %>% bb_add_style(y_grid = list( zero = list(line = "stroke: red", text = "font-size: 240%; fill: black" )))
# Change default color for regions billboarder() %>% bb_linechart(data = sin(seq(-pi, pi, length.out = 30))) %>% bb_regions( list(start = 0, end = 10, class = "custom"), # add custom class list(start = 19, end = 29, class = "foo") ) %>% bb_add_style(region = list(custom = "fill: red;", foo = "fill: #009246;")) # Customize grid line and text billboarder() %>% bb_linechart(data = sin(seq(-pi, pi, length.out = 30))) %>% bb_y_grid(lines = list(list( value = 0, text = "Zero", position = "middle", class = "zero" ))) %>% bb_add_style(y_grid = list( zero = list(line = "stroke: red", text = "font-size: 240%; fill: black" )))
Area property for a Billboard.js chart
bb_area(bb, ...)
bb_area(bb, ...)
bb |
A |
... |
See https://naver.github.io/billboard.js/release/latest/doc/Options.html#.area |
A billboard
htmlwidget
object.
Add axis parameters
bb_axis(bb, ...) bb_x_axis(bb, ...) bb_y_axis(bb, ...)
bb_axis(bb, ...) bb_x_axis(bb, ...) bb_y_axis(bb, ...)
bb |
A |
... |
Arguments defined in https://naver.github.io/billboard.js/demo/. |
A billboard
htmlwidget
object.
stars <- data.frame( package = c("billboarder", "ggiraph", "officer", "shinyWidgets", "visNetwork"), stars = c(9, 178, 43, 46, 175) ) # Add a label to y axis billboarder() %>% bb_barchart(data = stars) %>% bb_axis(y = list(label = list(text = "# of stars", position = "middle"))) # or shorter : billboarder() %>% bb_barchart(data = stars) %>% bb_y_axis(label = list(text = "# of stars", position = "outer-top"))
stars <- data.frame( package = c("billboarder", "ggiraph", "officer", "shinyWidgets", "visNetwork"), stars = c(9, 178, 43, 46, 175) ) # Add a label to y axis billboarder() %>% bb_barchart(data = stars) %>% bb_axis(y = list(label = list(text = "# of stars", position = "middle"))) # or shorter : billboarder() %>% bb_barchart(data = stars) %>% bb_y_axis(label = list(text = "# of stars", position = "outer-top"))
Bar property for a Billboard.js chart
bb_bar(bb, ...)
bb_bar(bb, ...)
bb |
A |
... |
See https://naver.github.io/billboard.js/release/latest/doc/Options.html#.bar |
A billboard
htmlwidget
object.
billboarder() %>% bb_barchart(data = data.frame(v1 = c("a", "b", "c"), value = c(5, 6, 3))) %>% bb_bar(width = list(ratio = 0.95))
billboarder() %>% bb_barchart(data = data.frame(v1 = c("a", "b", "c"), value = c(5, 6, 3))) %>% bb_bar(width = list(ratio = 0.95))
Manual color for barchart
bb_bar_color_manual(bb, values)
bb_bar_color_manual(bb, values)
bb |
A |
values |
A named vector, names represent the categories of the bar chart, values correspond to colors. All categories must be present in the vector, in the same order of the chart. |
A billboard
htmlwidget
object.
Must be called after bb_bar
.
## Not run: library("data.table") library("billboarder") data("mpg", package = "ggplot2") setDT(mpg) # all in blue manufa <- unique(mpg$manufacturer) cols <- rep("#08298A", length(manufa)) names(cols) <- manufa # Nissan in red cols[["nissan"]] <- "#DF0101"#' billboarder() %>% bb_barchart(data = mpg[, list(count = .N), by = manufacturer][order(count)]) %>% bb_bar_color_manual(values = cols) ## End(Not run)
## Not run: library("data.table") library("billboarder") data("mpg", package = "ggplot2") setDT(mpg) # all in blue manufa <- unique(mpg$manufacturer) cols <- rep("#08298A", length(manufa)) names(cols) <- manufa # Nissan in red cols[["nissan"]] <- "#DF0101"#' billboarder() %>% bb_barchart(data = mpg[, list(count = .N), by = manufacturer][order(count)]) %>% bb_bar_color_manual(values = cols) ## End(Not run)
Helper for creating a bar chart
bb_barchart( bb, data, mapping = NULL, stacked = FALSE, rotated = FALSE, color = NULL, ... )
bb_barchart( bb, data, mapping = NULL, stacked = FALSE, rotated = FALSE, color = NULL, ... )
bb |
A |
data |
A |
mapping |
Mapping of variables on the chart, see |
stacked |
Logical, if several columns are provided, produce a stacked bar chart, else a dodge bar chart. |
rotated |
Switch x and y axis position. |
color |
Bar's color. |
... |
Arguments for slot bar, see https://naver.github.io/billboard.js/release/latest/doc/Options.html#.bar. |
A billboard
htmlwidget
object.
This function can be used with billboarderProxy
in shiny application.
stars <- data.frame( package = c("billboarder", "ggiraph", "officer", "shinyWidgets", "visNetwork", "rAmCharts", "D3partitionR"), stars = c(67, 252, 160, 144, 224, 32, 25) ) # By default, first column is mapped on the x-axis # second one on the y axis billboarder() %>% bb_barchart(data = stars) # Specify explicitly the columns to use billboarder() %>% bb_barchart(data = stars, mapping = bbaes(package, stars), rotated = TRUE) # Add some options billboarder() %>% bb_barchart(data = stars[order(stars$stars), ], x = "package", y = "stars", rotated = TRUE) %>% bb_data(names = list(stars = "Number of stars")) %>% bb_y_grid(show = TRUE) # Hack stacked barcharts (to color bar) stars_wide <- data.frame( author = c("dreamRs", "davidgohel", "davidgohel", "dreamRs", "datastorm-open", "datastorm-open", "AntoineGuillot2"), package = c("billboarder", "ggiraph", "officer", "shinyWidgets", "visNetwork", "rAmCharts", "D3partitionR"), stars = c(67, 252, 160, 144, 224, 32, 25) ) billboarder() %>% bb_barchart(data = stars_wide, mapping = bbaes(package, stars, group = author), stacked = TRUE) billboarder() %>% bb_barchart(data = stars_wide, mapping = bbaes(author, stars, group = package), stacked = TRUE) # Grouping variable tab <- table(sample(letters[1:5], 100, TRUE), sample(LETTERS[1:5], 100, TRUE)) dat <- as.data.frame(tab) billboarder() %>% bb_barchart(data = dat, bbaes(x = Var1, y = Freq, group = Var2), rotated = TRUE) # You can also pass data in a 'wide' format dat2 <- data.frame( x = letters[1:5], A = sample.int(n = 100, size = 5), B = sample.int(n = 100, size = 5), C = sample.int(n = 100, size = 5), D = sample.int(n = 100, size = 5), E = sample.int(n = 100, size = 5) ) # But cannot use mapping billboarder() %>% bb_barchart(data = dat2, stacked = TRUE) %>% bb_data(order = NULL, labels = TRUE)
stars <- data.frame( package = c("billboarder", "ggiraph", "officer", "shinyWidgets", "visNetwork", "rAmCharts", "D3partitionR"), stars = c(67, 252, 160, 144, 224, 32, 25) ) # By default, first column is mapped on the x-axis # second one on the y axis billboarder() %>% bb_barchart(data = stars) # Specify explicitly the columns to use billboarder() %>% bb_barchart(data = stars, mapping = bbaes(package, stars), rotated = TRUE) # Add some options billboarder() %>% bb_barchart(data = stars[order(stars$stars), ], x = "package", y = "stars", rotated = TRUE) %>% bb_data(names = list(stars = "Number of stars")) %>% bb_y_grid(show = TRUE) # Hack stacked barcharts (to color bar) stars_wide <- data.frame( author = c("dreamRs", "davidgohel", "davidgohel", "dreamRs", "datastorm-open", "datastorm-open", "AntoineGuillot2"), package = c("billboarder", "ggiraph", "officer", "shinyWidgets", "visNetwork", "rAmCharts", "D3partitionR"), stars = c(67, 252, 160, 144, 224, 32, 25) ) billboarder() %>% bb_barchart(data = stars_wide, mapping = bbaes(package, stars, group = author), stacked = TRUE) billboarder() %>% bb_barchart(data = stars_wide, mapping = bbaes(author, stars, group = package), stacked = TRUE) # Grouping variable tab <- table(sample(letters[1:5], 100, TRUE), sample(LETTERS[1:5], 100, TRUE)) dat <- as.data.frame(tab) billboarder() %>% bb_barchart(data = dat, bbaes(x = Var1, y = Freq, group = Var2), rotated = TRUE) # You can also pass data in a 'wide' format dat2 <- data.frame( x = letters[1:5], A = sample.int(n = 100, size = 5), B = sample.int(n = 100, size = 5), C = sample.int(n = 100, size = 5), D = sample.int(n = 100, size = 5), E = sample.int(n = 100, size = 5) ) # But cannot use mapping billboarder() %>% bb_barchart(data = dat2, stacked = TRUE) %>% bb_data(order = NULL, labels = TRUE)
Bubble property for a Billboard.js chart
bb_bubble(bb, ...)
bb_bubble(bb, ...)
bb |
A |
... |
See https://naver.github.io/billboard.js/release/latest/doc/Options.html#.bubble |
A billboard
htmlwidget
object.
billboarder() %>% bb_scatterplot( data = iris, mapping = bbaes(Sepal.Length, Sepal.Width, group = Species, size = Petal.Width) ) %>% bb_bubble(maxR = 10) billboarder() %>% bb_scatterplot( data = iris, mapping = bbaes(Sepal.Length, Sepal.Width, group = Species, size = Petal.Width) ) %>% bb_bubble(maxR = JS("function(d) {return Math.sqrt(d.value.z * 20);}"))
billboarder() %>% bb_scatterplot( data = iris, mapping = bbaes(Sepal.Length, Sepal.Width, group = Species, size = Petal.Width) ) %>% bb_bubble(maxR = 10) billboarder() %>% bb_scatterplot( data = iris, mapping = bbaes(Sepal.Length, Sepal.Width, group = Species, size = Petal.Width) ) %>% bb_bubble(maxR = JS("function(d) {return Math.sqrt(d.value.z * 20);}"))
Callbacks for billboard charts
bb_callbacks( bb, onafterinit = NULL, onbeforeinit = NULL, oninit = NULL, onout = NULL, onover = NULL, onrendered = NULL, onresize = NULL, onresized = NULL )
bb_callbacks( bb, onafterinit = NULL, onbeforeinit = NULL, oninit = NULL, onout = NULL, onover = NULL, onrendered = NULL, onresize = NULL, onresized = NULL )
bb |
A |
onafterinit |
Set a callback to execute after the chart is initialized. |
onbeforeinit |
Set a callback to execute before the chart is initialized. |
oninit |
Set a callback to execute when the chart is initialized. |
onout |
Set a callback to execute when mouse/touch leaves the chart. |
onover |
Set a callback to execute when mouse/touch enters the chart. |
onrendered |
Set a callback which is executed when the chart is rendered. Basically, this callback will be called in each time when the chart is redrawed. |
onresize |
Set a callback to execute when user resizes the screen. |
onresized |
Set a callback to execute when screen resize finished. |
A billboard
htmlwidget
object.
Set JavaScript callbacks for various billboard events. See the billboard options reference for additional details on the signature of each callback.
Set or modify x axis labels.
bb_categories(bb, categories)
bb_categories(bb, categories)
bb |
A |
categories |
A character vector to set names on a category axis. |
A billboard
htmlwidget
object.
This function can be used with billboarder-shiny
to modify labels on axis, e.g. for barcharts.
# Simple line with month names as x labels billboarder() %>% bb_linechart(data = round(rnorm(12))) %>% bb_categories(categories = month.name)
# Simple line with month names as x labels billboarder() %>% bb_linechart(data = round(rnorm(12))) %>% bb_categories(categories = month.name)
Color property for a Billboard.js chart
bb_color(bb, palette = NULL, ...)
bb_color(bb, palette = NULL, ...)
bb |
A |
palette |
A color palette to use with series added in the chart. |
... |
See https://naver.github.io/billboard.js/release/latest/doc/Options.html#.color |
A billboard
htmlwidget
object.
library("RColorBrewer") # Scatter billboarder() %>% bb_scatterplot(data = iris, x = "Sepal.Length", y = "Sepal.Width", group = "Species") %>% bb_axis(x = list(tick = list(fit = FALSE))) %>% bb_point(r = 8) %>% bb_color(palette = brewer.pal(n = 3, name = "Reds")) # Pie stars <- data.frame( package = c("billboarder", "ggiraph", "officer", "shinyWidgets", "visNetwork"), stars = c(9, 177, 43, 44, 169) ) cols <- brewer.pal(n = 5, name = "Dark2") billboarder() %>% bb_piechart(data = stars) %>% bb_color(palette = brewer.pal(n = 5, name = "Reds"))
library("RColorBrewer") # Scatter billboarder() %>% bb_scatterplot(data = iris, x = "Sepal.Length", y = "Sepal.Width", group = "Species") %>% bb_axis(x = list(tick = list(fit = FALSE))) %>% bb_point(r = 8) %>% bb_color(palette = brewer.pal(n = 3, name = "Reds")) # Pie stars <- data.frame( package = c("billboarder", "ggiraph", "officer", "shinyWidgets", "visNetwork"), stars = c(9, 177, 43, 44, 169) ) cols <- brewer.pal(n = 5, name = "Dark2") billboarder() %>% bb_piechart(data = stars) %>% bb_color(palette = brewer.pal(n = 5, name = "Reds"))
Set colors for each datas
bb_colors_manual(bb, ..., opacity = 1)
bb_colors_manual(bb, ..., opacity = 1)
bb |
A |
... |
A named list, where names correspond to the data, and values to color associate with it. |
opacity |
Color opacity (for area charts). |
A billboard
htmlwidget
object.
library("RColorBrewer") # Scatter billboarder() %>% bb_scatterplot( data = iris, x = "Sepal.Length", y = "Sepal.Width", group = "Species" ) %>% bb_axis(x = list(tick = list(fit = FALSE))) %>% bb_point(r = 8) %>% bb_colors_manual( setosa = "#440154", virginica = "#21908C", versicolor = "#FDE725" ) # Pie stars <- data.frame( package = c("billboarder", "ggiraph", "officer", "shinyWidgets", "visNetwork"), stars = c(9, 177, 43, 44, 169) ) cols <- brewer.pal(n = 5, name = "Dark2") billboarder() %>% bb_piechart(data = stars) %>% bb_colors_manual( setNames(as.list(cols), stars$package) # this is a named list )
library("RColorBrewer") # Scatter billboarder() %>% bb_scatterplot( data = iris, x = "Sepal.Length", y = "Sepal.Width", group = "Species" ) %>% bb_axis(x = list(tick = list(fit = FALSE))) %>% bb_point(r = 8) %>% bb_colors_manual( setosa = "#440154", virginica = "#21908C", versicolor = "#FDE725" ) # Pie stars <- data.frame( package = c("billboarder", "ggiraph", "officer", "shinyWidgets", "visNetwork"), stars = c(9, 177, 43, 44, 169) ) cols <- brewer.pal(n = 5, name = "Dark2") billboarder() %>% bb_piechart(data = stars) %>% bb_colors_manual( setNames(as.list(cols), stars$package) # this is a named list )
Add data to Billboard chart
bb_data(bb, ...)
bb_data(bb, ...)
bb |
A |
... |
Arguments defined in https://naver.github.io/billboard.js/demo/. |
A billboard
htmlwidget
object.
This function can be used with billboarderProxy
in shiny application.
billboarder() %>% bb_barchart(data = table(mtcars$cyl)) %>% bb_data(names = list(Freq = "Number of cylinders"), labels = TRUE)
billboarder() %>% bb_barchart(data = table(mtcars$cyl)) %>% bb_data(names = list(Freq = "Number of cylinders"), labels = TRUE)
Helper for creating a density plot
bb_densityplot( bb, data, mapping = NULL, stacked = FALSE, stat = "density", fill = FALSE, ... )
bb_densityplot( bb, data, mapping = NULL, stacked = FALSE, stat = "density", fill = FALSE, ... )
bb |
A |
data |
A |
mapping |
Mapping of variables on the chart, see |
stacked |
Logical, create a stacked density plot. |
stat |
Stat to compute : |
fill |
Produce a conditional density estimate, this option force |
... |
Arguments passed to |
A billboard
htmlwidget
object.
# With a vector billboarder() %>% bb_densityplot(data = rnorm(1e4)) data("diamonds", package = "ggplot2") # density plot with one variable billboarder() %>% bb_densityplot(data = diamonds, x = "carat") # Same with mapping billboarder() %>% bb_densityplot(diamonds, bbaes(carat)) # With a grouping variable billboarder() %>% bb_densityplot(data = diamonds, x = "depth", group = "cut") %>% bb_x_axis(min = 55, max = 70) # Same with mapping billboarder() %>% bb_densityplot(diamonds, bbaes(depth, group = cut)) %>% bb_x_axis(min = 55, max = 70) # a stacked density plot using count as statistic bb <- billboarder() %>% bb_densityplot(diamonds, bbaes(depth, group = cut), stacked = TRUE, stat = "count") %>% bb_x_axis(min = 55, max = 70) bb # changing order bb %>% bb_data(order = "asc")
# With a vector billboarder() %>% bb_densityplot(data = rnorm(1e4)) data("diamonds", package = "ggplot2") # density plot with one variable billboarder() %>% bb_densityplot(data = diamonds, x = "carat") # Same with mapping billboarder() %>% bb_densityplot(diamonds, bbaes(carat)) # With a grouping variable billboarder() %>% bb_densityplot(data = diamonds, x = "depth", group = "cut") %>% bb_x_axis(min = 55, max = 70) # Same with mapping billboarder() %>% bb_densityplot(diamonds, bbaes(depth, group = cut)) %>% bb_x_axis(min = 55, max = 70) # a stacked density plot using count as statistic bb <- billboarder() %>% bb_densityplot(diamonds, bbaes(depth, group = cut), stacked = TRUE, stat = "count") %>% bb_x_axis(min = 55, max = 70) bb # changing order bb %>% bb_data(order = "asc")
Donut property for a Billboard.js chart
bb_donut(bb, ...)
bb_donut(bb, ...)
bb |
A |
... |
See https://naver.github.io/billboard.js/release/latest/doc/Options.html#.donut |
A billboard
htmlwidget
object.
billboarder() %>% bb_donutchart(data = table(mtcars$cyl)) %>% bb_donut(title = "Donut Title", width = 10)
billboarder() %>% bb_donutchart(data = table(mtcars$cyl)) %>% bb_donut(title = "Donut Title", width = 10)
Helper for creating a donut chart
bb_donutchart(bb, data, mapping = NULL, ...)
bb_donutchart(bb, data, mapping = NULL, ...)
bb |
A |
data |
A |
mapping |
Mapping of variables on the chart, see |
... |
Arguments for slot donut, https://naver.github.io/billboard.js/release/latest/doc/Options.html#.donut. |
A billboard
htmlwidget
object.
This function can be used with billboarderProxy
in shiny application.
## Not run: stars <- data.frame( package = c("billboarder", "ggiraph", "officer", "shinyWidgets", "visNetwork"), stars = c(9, 177, 43, 44, 169) ) billboarder() %>% bb_donutchart(data = stars, title = "Stars") ## End(Not run)
## Not run: stars <- data.frame( package = c("billboarder", "ggiraph", "officer", "shinyWidgets", "visNetwork"), stars = c(9, 177, 43, 44, 169) ) billboarder() %>% bb_donutchart(data = stars, title = "Stars") ## End(Not run)
Export a Billboard to PNG
bb_export(bb, filename = NULL, download_label = "Export (.png)", ...)
bb_export(bb, filename = NULL, download_label = "Export (.png)", ...)
bb |
A |
filename |
A string of the filename, excluding extension (will be |
download_label |
Label to appear on the link to download PNG. |
... |
Additional arguments (not used). |
A billboard
htmlwidget
object.
This function has two uses:
in shiny: you can export to PNG with an observeEvent
by using billboarderProxy
.
in markdown and in shiny: add a button to download chart as PNG.
# Add a button to download as PNG: data("equilibre_mensuel") billboarder() %>% bb_linechart( data = equilibre_mensuel, mapping = bbaes(date, solde), type = "spline" ) %>% bb_x_axis( tick = list(format = "%Y-%m", fit = FALSE) ) %>% bb_export( filename = "my-awesome-chart", download_label = "Click to download" ) # In shiny, you can use proxy : if (interactive()) { library(shiny) library(billboarder) ui <- fluidPage( fluidRow( column( width = 8, offset = 2, tags$h1("Export billboard as PNG via Proxy"), billboarderOutput(outputId = "mybb"), actionButton( inputId = "export", label = "Export", icon = icon("download") ) ) ) ) server <- function(input, output, session) { output$mybb <- renderBillboarder({ data("prod_par_filiere") billboarder() %>% bb_barchart( data = prod_par_filiere[, c("annee", "prod_hydraulique")], color = "#102246" ) %>% bb_y_grid(show = TRUE) }) observeEvent(input$export, { billboarderProxy(shinyId = "mybb") %>% bb_export(filename = "my-billboard-chart") }) } shinyApp(ui, server) }
# Add a button to download as PNG: data("equilibre_mensuel") billboarder() %>% bb_linechart( data = equilibre_mensuel, mapping = bbaes(date, solde), type = "spline" ) %>% bb_x_axis( tick = list(format = "%Y-%m", fit = FALSE) ) %>% bb_export( filename = "my-awesome-chart", download_label = "Click to download" ) # In shiny, you can use proxy : if (interactive()) { library(shiny) library(billboarder) ui <- fluidPage( fluidRow( column( width = 8, offset = 2, tags$h1("Export billboard as PNG via Proxy"), billboarderOutput(outputId = "mybb"), actionButton( inputId = "export", label = "Export", icon = icon("download") ) ) ) ) server <- function(input, output, session) { output$mybb <- renderBillboarder({ data("prod_par_filiere") billboarder() %>% bb_barchart( data = prod_par_filiere[, c("annee", "prod_hydraulique")], color = "#102246" ) %>% bb_y_grid(show = TRUE) }) observeEvent(input$export, { billboarderProxy(shinyId = "mybb") %>% bb_export(filename = "my-billboard-chart") }) } shinyApp(ui, server) }
Gauge property for a Billboard.js chart
bb_gauge(bb, ...)
bb_gauge(bb, ...)
bb |
A |
... |
See https://naver.github.io/billboard.js/release/latest/doc/Options.html#.gauge |
A billboard
htmlwidget
object.
billboarder() %>% bb_gaugechart(value = 50) %>% bb_gauge(min = 0, max = 200, units = "km/h", width = 10, label = list(format = htmlwidgets::JS("function(value) {return value;}")))
billboarder() %>% bb_gaugechart(value = 50) %>% bb_gauge(min = 0, max = 200, units = "km/h", width = 10, label = list(format = htmlwidgets::JS("function(value) {return value;}")))
Helper for creating a gauge
bb_gaugechart( bb, value, name = "Value", color = NULL, steps = c(30, 60, 90, 100), steps_color = c("#FF0000", "#F97600", "#F6C600", "#60B044"), ... )
bb_gaugechart( bb, value, name = "Value", color = NULL, steps = c(30, 60, 90, 100), steps_color = c("#FF0000", "#F97600", "#F6C600", "#60B044"), ... )
bb |
A |
value |
A single numeric value or a vector for stacked gauge. |
name |
Name for the value, appear in tooltip, same length as 'value'. |
color |
Color for the gauge, if provided, 'steps' and 'steps_color' are ignored. |
steps |
Upper bound for changing colors |
steps_color |
Colors corresponding to steps |
... |
Arguments for slot gauge. |
A billboard
htmlwidget
object.
This function can be used with billboarderProxy
in shiny application.
billboarder() %>% bb_gaugechart(value = 50) # With some options billboarder() %>% bb_gaugechart( value = 160, steps_color = rev(c("#FF0000", "#F97600", "#F6C600", "#60B044")) ) %>% bb_gauge( label = list(format = suffix("km/h")), min = 10, max = 200, width = 20 )
billboarder() %>% bb_gaugechart(value = 50) # With some options billboarder() %>% bb_gaugechart( value = 160, steps_color = rev(c("#FF0000", "#F97600", "#F6C600", "#60B044")) ) %>% bb_gauge( label = list(format = suffix("km/h")), min = 10, max = 200, width = 20 )
Grid property for a Billboard.js chart
bb_grid(bb, ...) bb_x_grid(bb, ...) bb_y_grid(bb, ...)
bb_grid(bb, ...) bb_x_grid(bb, ...) bb_y_grid(bb, ...)
bb |
A |
... |
See https://naver.github.io/billboard.js/release/latest/doc/Options.html#.grid |
A billboard
htmlwidget
object.
bb_x_grid
and bb_y_grid
are shortcut for modifying the x-axis and the y-axis respectively.
stars <- data.frame( package = c("billboarder", "ggiraph", "officer", "shinyWidgets", "visNetwork"), stars = c(1, 176, 42, 40, 166) ) billboarder() %>% bb_barchart(data = stars) %>% bb_y_grid(show = TRUE) billboarder() %>% bb_barchart(data = stars) %>% bb_y_grid(lines = list(list(value = mean(stars$stars), text = "Horizontal line")))
stars <- data.frame( package = c("billboarder", "ggiraph", "officer", "shinyWidgets", "visNetwork"), stars = c(1, 176, 42, 40, 166) ) billboarder() %>% bb_barchart(data = stars) %>% bb_y_grid(show = TRUE) billboarder() %>% bb_barchart(data = stars) %>% bb_y_grid(lines = list(list(value = mean(stars$stars), text = "Horizontal line")))
Helper for creating an histogram
bb_histogram( bb, data, mapping = NULL, stacked = FALSE, fill = FALSE, bins = 30, binwidth = NULL, ... )
bb_histogram( bb, data, mapping = NULL, stacked = FALSE, fill = FALSE, bins = 30, binwidth = NULL, ... )
bb |
A |
data |
A |
mapping |
Mapping of variables on the chart, see |
stacked |
Logical, create a stacked histogram. |
fill |
Logical, create a stacked percentage histogram. |
bins |
Number of bins. Overridden by |
binwidth |
The width of the bins. See |
... |
Not used. |
A billboard
htmlwidget
object.
data("diamonds", package = "ggplot2") # one variable billboarder() %>% bb_histogram(data = diamonds, x = "price") # with mapping billboarder() %>% bb_histogram(diamonds, bbaes(price)) # equivalent to billboarder() %>% bb_histogram(data = diamonds$price) # prettier with 'binwidth' # (but you need to know your data) billboarder() %>% bb_histogram(data = diamonds, x = "price", binwidth = 500) %>% bb_colors_manual() # with a grouping variable billboarder() %>% bb_histogram(data = diamonds, x = "price", group = "cut", binwidth = 500) # and with mapping billboarder() %>% bb_histogram(diamonds, bbaes(price, group = cut), binwidth = 500) # stacked histogram billboarder() %>% bb_histogram(diamonds, bbaes(price, group = cut), stacked = TRUE, binwidth = 500) # another example dat <- data.frame( sample = c(rnorm(n = 500, mean = 1), rnorm(n = 500, mean = 2)), group = rep(c("A", "B"), each = 500) ) billboarder() %>% bb_histogram(data = dat, x = "sample", binwidth = 0.25) samples_mean <- tapply(dat$sample, dat$group, mean) billboarder() %>% bb_histogram(data = dat, x = "sample", group = "group", binwidth = 0.25) %>% bb_x_grid( lines = list( list(value = unname(samples_mean['A']), text = "mean of sample A"), list(value = unname(samples_mean['B']), text = "mean of sample B") ) )
data("diamonds", package = "ggplot2") # one variable billboarder() %>% bb_histogram(data = diamonds, x = "price") # with mapping billboarder() %>% bb_histogram(diamonds, bbaes(price)) # equivalent to billboarder() %>% bb_histogram(data = diamonds$price) # prettier with 'binwidth' # (but you need to know your data) billboarder() %>% bb_histogram(data = diamonds, x = "price", binwidth = 500) %>% bb_colors_manual() # with a grouping variable billboarder() %>% bb_histogram(data = diamonds, x = "price", group = "cut", binwidth = 500) # and with mapping billboarder() %>% bb_histogram(diamonds, bbaes(price, group = cut), binwidth = 500) # stacked histogram billboarder() %>% bb_histogram(diamonds, bbaes(price, group = cut), stacked = TRUE, binwidth = 500) # another example dat <- data.frame( sample = c(rnorm(n = 500, mean = 1), rnorm(n = 500, mean = 2)), group = rep(c("A", "B"), each = 500) ) billboarder() %>% bb_histogram(data = dat, x = "sample", binwidth = 0.25) samples_mean <- tapply(dat$sample, dat$group, mean) billboarder() %>% bb_histogram(data = dat, x = "sample", group = "group", binwidth = 0.25) %>% bb_x_grid( lines = list( list(value = unname(samples_mean['A']), text = "mean of sample A"), list(value = unname(samples_mean['B']), text = "mean of sample B") ) )
Interaction property for a Billboard.js chart
bb_interaction(bb, ...)
bb_interaction(bb, ...)
bb |
A |
... |
See https://naver.github.io/billboard.js/release/latest/doc/Options.html#.interaction |
A billboard
htmlwidget
object.
Quickly set title, axis labels and caption
bb_labs(bb, title = NULL, x = NULL, y = NULL, caption = NULL, ...)
bb_labs(bb, title = NULL, x = NULL, y = NULL, caption = NULL, ...)
bb |
A |
title |
Text for the chart title, use |
x |
Text for x axis title. |
y |
Text for y axis title. |
caption |
Text for the caption displayed in the bottom-right of the chart. |
... |
Not used. |
A billboard
htmlwidget
object.
caption
is not part of the billboard.js library, it is added by the billboarder
package.
data("prod_par_filiere") billboarder() %>% bb_barchart( data = prod_par_filiere[, c("annee", "prod_hydraulique")], color = "#102246" ) %>% bb_legend(show = FALSE) %>% bb_labs( title = "French hydraulic production", y = "production (in terawatt-hours)", caption = "Data source: RTE (https://opendata.reseaux-energies.fr/)", caption_href = "https://opendata.reseaux-energies.fr/" )
data("prod_par_filiere") billboarder() %>% bb_barchart( data = prod_par_filiere[, c("annee", "prod_hydraulique")], color = "#102246" ) %>% bb_legend(show = FALSE) %>% bb_labs( title = "French hydraulic production", y = "production (in terawatt-hours)", caption = "Data source: RTE (https://opendata.reseaux-energies.fr/)", caption_href = "https://opendata.reseaux-energies.fr/" )
Add legend parameters
bb_legend(bb, ...)
bb_legend(bb, ...)
bb |
A |
... |
Arguments defined in https://naver.github.io/billboard.js/release/latest/doc/Options.html#.legend. |
A billboard
htmlwidget
object.
library("billboarder") stars <- data.frame( package = c("billboarder", "ggiraph", "officer", "shinyWidgets", "visNetwork"), stars = c(1, 176, 42, 40, 166) ) # Hide legend billboarder() %>% bb_barchart(data = stars) %>% bb_legend(show = FALSE) # Right legend billboarder() %>% bb_piechart(data = stars) %>% bb_legend(position = "right") # Inset legend billboarder() %>% bb_scatterplot(data = iris, x = "Sepal.Length", y = "Sepal.Width", group = "Species") %>% bb_axis(x = list(tick = list(fit = FALSE))) %>% bb_legend(position = "inset", inset = list(anchor = "top-right"))
library("billboarder") stars <- data.frame( package = c("billboarder", "ggiraph", "officer", "shinyWidgets", "visNetwork"), stars = c(1, 176, 42, 40, 166) ) # Hide legend billboarder() %>% bb_barchart(data = stars) %>% bb_legend(show = FALSE) # Right legend billboarder() %>% bb_piechart(data = stars) %>% bb_legend(position = "right") # Inset legend billboarder() %>% bb_scatterplot(data = iris, x = "Sepal.Length", y = "Sepal.Width", group = "Species") %>% bb_axis(x = list(tick = list(fit = FALSE))) %>% bb_legend(position = "inset", inset = list(anchor = "top-right"))
Line property for a Billboard.js chart
bb_line(bb, ...)
bb_line(bb, ...)
bb |
A |
... |
See https://naver.github.io/billboard.js/release/latest/doc/Options.html#.line |
A billboard
htmlwidget
object.
# Set if null data point will be connected or not. b <- billboarder() %>% bb_linechart(data = c(1, 2, NA, 4, 5)) b b %>% bb_line(connectNull = TRUE)
# Set if null data point will be connected or not. b <- billboarder() %>% bb_linechart(data = c(1, 2, NA, 4, 5)) b b %>% bb_line(connectNull = TRUE)
Helper for creating a line chart
bb_linechart( bb, data, mapping = NULL, type = "line", show_point = FALSE, dasharray = NULL, width = NULL, ... )
bb_linechart( bb, data, mapping = NULL, type = "line", show_point = FALSE, dasharray = NULL, width = NULL, ... )
bb |
A |
data |
A |
mapping |
Mapping of variables on the chart, see |
type |
Type of chart : |
show_point |
Whether to show each point in line. |
dasharray |
Pattern of dashes and gaps used to paint the outline of the line, see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray for specifications. |
width |
Width of the stroke to be applied to the line, see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-width for specifications. |
... |
Not used. |
A billboard
htmlwidget
object.
Types area-line-range and area-spline-range don't work in RStudio viewer, open chart in a browser.
This function can be used with billboarderProxy
in shiny application.
## Different types x <- round(rnorm(20), 2) billboarder() %>% bb_linechart(data = x) billboarder() %>% bb_linechart(data = x, type = "spline") billboarder() %>% bb_linechart(data = x, type = "area") billboarder() %>% bb_linechart(data = x, type = "area-spline") ## Timeserie with date (Date) data("economics", package = "ggplot2") billboarder() %>% bb_linechart(data = economics[, c("date", "psavert")]) %>% bb_x_axis(tick = list(format = "%Y-%m", fit = FALSE)) %>% bb_y_axis(tick = list(format = suffix("%")), label = list(text = "Personal savings rate")) %>% bb_legend(show = FALSE) %>% bb_x_grid(show = TRUE) %>% bb_y_grid(show = TRUE) %>% bb_subchart(show = TRUE) # With multiple lines : data("economics_long", package = "ggplot2") billboarder() %>% bb_linechart(economics_long, bbaes(date, value, variable)) %>% bb_data(hide = "pop") %>% bb_x_axis(tick = list(format = "%Y-%m", fit = FALSE)) ## Timeserie with datetime (POSIXct) data("cdc_prod_filiere") billboarder() %>% bb_linechart(data = cdc_prod_filiere[, c("date_heure", "prod_eolien")]) # or with mapping : billboarder() %>% bb_linechart(cdc_prod_filiere, bbaes(date_heure, prod_bioenergies)) ### Other type for x-axis ## character/factor on x-axis AirPassengers1960 <- data.frame( month = month.name, AirPassengers = tail(AirPassengers, 12) ) # you have to specify that x-axis is of type 'category' # and that column 'month' must be used for x-axis values billboarder() %>% bb_linechart(data = AirPassengers1960, x = "month") %>% bb_x_axis(type = "category") ## numeric on x-axis lynx.df <- data.frame( year = time(lynx), lynx = lynx ) # just specify which variable must be use n the x-axis billboarder() %>% bb_linechart(data = lynx.df, x = "year") ### Area range charts # Generate data dat <- data.frame( date = seq.Date(Sys.Date(), length.out = 20, by = "day"), y1 = round(rnorm(20, 100, 15)), y2 = round(rnorm(20, 100, 15)) ) dat$ymin1 <- dat$y1 - 5 dat$ymax1 <- dat$y1 + 5 dat$ymin2 <- dat$y2 - sample(3:15, 20, TRUE) dat$ymax2 <- dat$y2 + sample(3:15, 20, TRUE) # Make chart : use ymin & ymax aes for range billboarder(data = dat) %>% bb_linechart( mapping = bbaes(x = date, y = y1, ymin = ymin1, ymax = ymax1), type = "area-line-range" ) %>% bb_linechart( mapping = bbaes(x = date, y = y2, ymin = ymin2, ymax = ymax2), type = "area-spline-range" ) %>% bb_y_axis(min = 50)
## Different types x <- round(rnorm(20), 2) billboarder() %>% bb_linechart(data = x) billboarder() %>% bb_linechart(data = x, type = "spline") billboarder() %>% bb_linechart(data = x, type = "area") billboarder() %>% bb_linechart(data = x, type = "area-spline") ## Timeserie with date (Date) data("economics", package = "ggplot2") billboarder() %>% bb_linechart(data = economics[, c("date", "psavert")]) %>% bb_x_axis(tick = list(format = "%Y-%m", fit = FALSE)) %>% bb_y_axis(tick = list(format = suffix("%")), label = list(text = "Personal savings rate")) %>% bb_legend(show = FALSE) %>% bb_x_grid(show = TRUE) %>% bb_y_grid(show = TRUE) %>% bb_subchart(show = TRUE) # With multiple lines : data("economics_long", package = "ggplot2") billboarder() %>% bb_linechart(economics_long, bbaes(date, value, variable)) %>% bb_data(hide = "pop") %>% bb_x_axis(tick = list(format = "%Y-%m", fit = FALSE)) ## Timeserie with datetime (POSIXct) data("cdc_prod_filiere") billboarder() %>% bb_linechart(data = cdc_prod_filiere[, c("date_heure", "prod_eolien")]) # or with mapping : billboarder() %>% bb_linechart(cdc_prod_filiere, bbaes(date_heure, prod_bioenergies)) ### Other type for x-axis ## character/factor on x-axis AirPassengers1960 <- data.frame( month = month.name, AirPassengers = tail(AirPassengers, 12) ) # you have to specify that x-axis is of type 'category' # and that column 'month' must be used for x-axis values billboarder() %>% bb_linechart(data = AirPassengers1960, x = "month") %>% bb_x_axis(type = "category") ## numeric on x-axis lynx.df <- data.frame( year = time(lynx), lynx = lynx ) # just specify which variable must be use n the x-axis billboarder() %>% bb_linechart(data = lynx.df, x = "year") ### Area range charts # Generate data dat <- data.frame( date = seq.Date(Sys.Date(), length.out = 20, by = "day"), y1 = round(rnorm(20, 100, 15)), y2 = round(rnorm(20, 100, 15)) ) dat$ymin1 <- dat$y1 - 5 dat$ymax1 <- dat$y1 + 5 dat$ymin2 <- dat$y2 - sample(3:15, 20, TRUE) dat$ymax2 <- dat$y2 + sample(3:15, 20, TRUE) # Make chart : use ymin & ymax aes for range billboarder(data = dat) %>% bb_linechart( mapping = bbaes(x = date, y = y1, ymin = ymin1, ymax = ymax1), type = "area-line-range" ) %>% bb_linechart( mapping = bbaes(x = date, y = y2, ymin = ymin2, ymax = ymax2), type = "area-spline-range" ) %>% bb_y_axis(min = 50)
Load data to the chart with proxy
bb_load(proxy, data = NULL, unload = NULL, ...)
bb_load(proxy, data = NULL, unload = NULL, ...)
proxy |
A |
data |
A |
unload |
Ids (names) to data to unload. |
... |
Arguments passed to method. |
A billboardProxy
htmlwidget
object.
Helper for creating a lollipop chart
bb_lollipop( bb, data, mapping = NULL, rotated = FALSE, point_color = "#112446", point_size = 8, line_color = "#000", ... )
bb_lollipop( bb, data, mapping = NULL, rotated = FALSE, point_color = "#112446", point_size = 8, line_color = "#000", ... )
bb |
A |
data |
A |
mapping |
Mapping of variables on the chart, see |
rotated |
Switch x and y axis position. |
point_color |
Color of the lollipop. |
point_size |
Size of the lollipop. |
line_color |
Color of the lines between the axis and the lollipop. |
... |
Not used. |
A billboard
htmlwidget
object.
# From wikipedia sw <- data.frame( film = c("The Force Awakens", "The Phantom Menace", "Revenge of the Sith", "A New Hope", "Attack of the Clones", "The Empire Strikes Back", "Return of the Jedi" ), worldwide_gross = c(2068178225, 1027044677, 848754768, 775398007, 649398328, 538375067, 475106177) ) # Simple example billboarder() %>% bb_lollipop(data = sw) # Fancy example billboarder() %>% bb_lollipop(data = sw, rotated = TRUE)%>% bb_y_grid(show = TRUE) %>% bb_y_axis(tick = list( values = c(0, 5e+08, 1e+09, 1.5e+09, 2e+09), outer = FALSE, format = htmlwidgets::JS("d3.formatPrefix('$,.0', 1e6)") )) %>% bb_x_axis(tick = list(centered = TRUE)) %>% bb_labs( title = "Star Wars - Total Lifetime Grosses", caption = "Data source : wikipedia" ) # With mapping billboarder(data = sw) %>% bb_lollipop(mapping = bbaes(x = film, y = worldwide_gross))
# From wikipedia sw <- data.frame( film = c("The Force Awakens", "The Phantom Menace", "Revenge of the Sith", "A New Hope", "Attack of the Clones", "The Empire Strikes Back", "Return of the Jedi" ), worldwide_gross = c(2068178225, 1027044677, 848754768, 775398007, 649398328, 538375067, 475106177) ) # Simple example billboarder() %>% bb_lollipop(data = sw) # Fancy example billboarder() %>% bb_lollipop(data = sw, rotated = TRUE)%>% bb_y_grid(show = TRUE) %>% bb_y_axis(tick = list( values = c(0, 5e+08, 1e+09, 1.5e+09, 2e+09), outer = FALSE, format = htmlwidgets::JS("d3.formatPrefix('$,.0', 1e6)") )) %>% bb_x_axis(tick = list(centered = TRUE)) %>% bb_labs( title = "Star Wars - Total Lifetime Grosses", caption = "Data source : wikipedia" ) # With mapping billboarder(data = sw) %>% bb_lollipop(mapping = bbaes(x = film, y = worldwide_gross))
The padding of the chart element.
bb_padding(bb, ...)
bb_padding(bb, ...)
bb |
A |
... |
See https://naver.github.io/billboard.js/release/latest/doc/Options.html#.padding for possible options. |
A billboard
htmlwidget
object.
Pie property for a Billboard.js chart
bb_pie(bb, ...)
bb_pie(bb, ...)
bb |
A |
... |
See https://naver.github.io/billboard.js/release/latest/doc/Options.html#.pie |
A billboard
htmlwidget
object.
billboarder() %>% bb_piechart(data = table(mtcars$cyl)) %>% bb_pie(label = list( ratio = 0.5, format = htmlwidgets::JS("function(value) {return d3.format('$')(value);}") ), expand = FALSE)
billboarder() %>% bb_piechart(data = table(mtcars$cyl)) %>% bb_pie(label = list( ratio = 0.5, format = htmlwidgets::JS("function(value) {return d3.format('$')(value);}") ), expand = FALSE)
Helper for creating a pie chart
bb_piechart(bb, data, mapping = NULL, ...)
bb_piechart(bb, data, mapping = NULL, ...)
bb |
A |
data |
A |
mapping |
Mapping of variables on the chart, see |
... |
Arguments for slot pie, https://naver.github.io/billboard.js/release/latest/doc/Options.html#.pie. |
A billboard
htmlwidget
object.
This function can be used with billboarderProxy
in shiny application.
stars <- data.frame( package = c("billboarder", "ggiraph", "officer", "shinyWidgets", "visNetwork"), stars = c(9, 177, 43, 44, 169) ) # Default billboarder() %>% bb_piechart(data = stars) # Explicit mapping billboarder() %>% bb_piechart(data = stars, bbaes(package, stars)) # Other way to specify mapping billboarder(data = stars) %>% bb_aes(package, stars) %>% bb_piechart()
stars <- data.frame( package = c("billboarder", "ggiraph", "officer", "shinyWidgets", "visNetwork"), stars = c(9, 177, 43, 44, 169) ) # Default billboarder() %>% bb_piechart(data = stars) # Explicit mapping billboarder() %>% bb_piechart(data = stars, bbaes(package, stars)) # Other way to specify mapping billboarder(data = stars) %>% bb_aes(package, stars) %>% bb_piechart()
Point property for a Billboard.js chart
bb_point(bb, ...)
bb_point(bb, ...)
bb |
A |
... |
See https://naver.github.io/billboard.js/release/latest/doc/Options.html#.point |
A billboard
htmlwidget
object.
# Set point size billboarder() %>% bb_scatterplot(data = iris, x = "Sepal.Length", y = "Sepal.Width", group = "Species") %>% bb_axis(x = list(tick = list(fit = FALSE))) %>% bb_point(r = 10)
# Set point size billboarder() %>% bb_scatterplot(data = iris, x = "Sepal.Length", y = "Sepal.Width", group = "Species") %>% bb_axis(x = list(tick = list(fit = FALSE))) %>% bb_point(r = 10)
Update axis labels with proxy
bb_proxy_axis_labels(proxy, x = NULL, y = NULL)
bb_proxy_axis_labels(proxy, x = NULL, y = NULL)
proxy |
A |
x |
X axis label. |
y |
Y axis label. |
A billboardProxy
htmlwidget
object.
Change colors with proxy
bb_proxy_data_colors(proxy, names = NULL, colors = NULL)
bb_proxy_data_colors(proxy, names = NULL, colors = NULL)
proxy |
A |
names |
Names of series |
colors |
New colors, in same order that |
A billboardProxy
htmlwidget
object.
if (interactive()) { library(shiny) library(billboarder) ui <- fluidPage( tags$h2("Update colors"), fluidRow( column( width = 3, selectizeInput( inputId = "col_eol", label = "Color for 'prod_eolien':", choices = c("#66C2A5", "#FC8D62", "#8DA0CB", "#E78AC3", "#A6D854", "#FFD92F", "#E5C494", "#B3B3B3") ), selectizeInput( inputId = "col_sol", label = "Color for 'prod_solaire':", choices = c("#66C2A5", "#FC8D62", "#8DA0CB", "#E78AC3", "#A6D854", "#FFD92F", "#E5C494", "#B3B3B3") ) ), column( width = 9, billboarderOutput(outputId = "my_bb") ) ) ) server <- function(input, output, session) { output$my_bb <- renderBillboarder({ data(prod_par_filiere) billboarder() %>% bb_barchart( data = prod_par_filiere[, c(1, 6, 8)] ) }) observe({ billboarderProxy(shinyId = "my_bb") %>% bb_proxy_data_colors( names = c("prod_eolien", "prod_solaire"), colors = c(input$col_eol, input$col_sol) ) }) } shinyApp(ui, server) }
if (interactive()) { library(shiny) library(billboarder) ui <- fluidPage( tags$h2("Update colors"), fluidRow( column( width = 3, selectizeInput( inputId = "col_eol", label = "Color for 'prod_eolien':", choices = c("#66C2A5", "#FC8D62", "#8DA0CB", "#E78AC3", "#A6D854", "#FFD92F", "#E5C494", "#B3B3B3") ), selectizeInput( inputId = "col_sol", label = "Color for 'prod_solaire':", choices = c("#66C2A5", "#FC8D62", "#8DA0CB", "#E78AC3", "#A6D854", "#FFD92F", "#E5C494", "#B3B3B3") ) ), column( width = 9, billboarderOutput(outputId = "my_bb") ) ) ) server <- function(input, output, session) { output$my_bb <- renderBillboarder({ data(prod_par_filiere) billboarder() %>% bb_barchart( data = prod_par_filiere[, c(1, 6, 8)] ) }) observe({ billboarderProxy(shinyId = "my_bb") %>% bb_proxy_data_colors( names = c("prod_eolien", "prod_solaire"), colors = c(input$col_eol, input$col_sol) ) }) } shinyApp(ui, server) }
Change names of the data with proxy
bb_proxy_data_names(proxy, old = NULL, new = NULL)
bb_proxy_data_names(proxy, old = NULL, new = NULL)
proxy |
A |
old |
Old names |
new |
New names |
A billboardProxy
htmlwidget
object.
if (interactive()) { library(shiny) library(billboarder) ui <- fluidPage( tags$h2("Update axis title & data name (tooltip & legend)"), billboarderOutput(outputId = "my_bb"), textInput( inputId = "new_name", label = "New name :", value = "this is a new name", width = "100%" ), actionButton( inputId = "update", label = "Update chart", width = "100%" ) ) server <- function(input, output, session) { output$my_bb <- renderBillboarder({ dat <- sample(letters[1:5], 100, TRUE) billboarder() %>% bb_barchart(data = table(dat)) %>% bb_y_axis(label = list(text = "Freq")) }) observeEvent(input$update, { dat <- sample(letters[1:5], 100, TRUE) billboarderProxy(shinyId = "my_bb") %>% bb_proxy_axis_labels(y = input$new_name) %>% bb_proxy_data_names(old = "Freq", new = input$new_name) %>% bb_barchart(data = table(dat)) }, ignoreInit = TRUE) } shinyApp(ui, server) }
if (interactive()) { library(shiny) library(billboarder) ui <- fluidPage( tags$h2("Update axis title & data name (tooltip & legend)"), billboarderOutput(outputId = "my_bb"), textInput( inputId = "new_name", label = "New name :", value = "this is a new name", width = "100%" ), actionButton( inputId = "update", label = "Update chart", width = "100%" ) ) server <- function(input, output, session) { output$my_bb <- renderBillboarder({ dat <- sample(letters[1:5], 100, TRUE) billboarder() %>% bb_barchart(data = table(dat)) %>% bb_y_axis(label = list(text = "Freq")) }) observeEvent(input$update, { dat <- sample(letters[1:5], 100, TRUE) billboarderProxy(shinyId = "my_bb") %>% bb_proxy_axis_labels(y = input$new_name) %>% bb_proxy_data_names(old = "Freq", new = input$new_name) %>% bb_barchart(data = table(dat)) }, ignoreInit = TRUE) } shinyApp(ui, server) }
Update chart flow with proxy
bb_proxy_flow(proxy, ...)
bb_proxy_flow(proxy, ...)
proxy |
A |
... |
Arguments passed to the flow API, see https://naver.github.io/billboard.js/release/latest/doc/Chart.html#flow. |
A billboardProxy
htmlwidget
object.
if (interactive()) { library(shiny) library(billboarder) ui <- fluidPage( tags$h3("Proxy flow"), actionButton( inputId = "next_data", label = "Add data", icon = icon("arrow-right") ), billboarderOutput(outputId = "chart1"), tags$h4("Real time chart"), billboarderOutput(outputId = "chart2") ) server <- function(input, output, session) { time_data <- reactiveValues(df = data.frame( x = Sys.Date() + 1:20, y = round(rnorm(20) * 10) )) output$chart1 <- renderBillboarder({ billboarder() %>% bb_linechart(data = isolate(time_data$df)) }) observeEvent(input$next_data, { time_data$df$x <- time_data$df$x + 21 time_data$df$y <- round(rnorm(20) * 10) }) observe({ billboarderProxy("chart1") %>% bb_proxy_flow(json = as.list(time_data$df), duration = 1500) }) output$chart2 <- renderBillboarder({ df <- data.frame( x = Sys.time() - 1:20 * 2, y = round(rnorm(20) * 10) ) billboarder() %>% bb_linechart(data = df) %>% bb_x_axis(tick = list(format = "%H:%M", fit = FALSE)) }) observe({ invalidateLater(2000) billboarderProxy("chart2") %>% bb_proxy_flow(json = list( x = list(format(Sys.time())), y = list(round(rnorm(1) * 10)) ), data = list(x = "x")) }) } shinyApp(ui, server) }
if (interactive()) { library(shiny) library(billboarder) ui <- fluidPage( tags$h3("Proxy flow"), actionButton( inputId = "next_data", label = "Add data", icon = icon("arrow-right") ), billboarderOutput(outputId = "chart1"), tags$h4("Real time chart"), billboarderOutput(outputId = "chart2") ) server <- function(input, output, session) { time_data <- reactiveValues(df = data.frame( x = Sys.Date() + 1:20, y = round(rnorm(20) * 10) )) output$chart1 <- renderBillboarder({ billboarder() %>% bb_linechart(data = isolate(time_data$df)) }) observeEvent(input$next_data, { time_data$df$x <- time_data$df$x + 21 time_data$df$y <- round(rnorm(20) * 10) }) observe({ billboarderProxy("chart1") %>% bb_proxy_flow(json = as.list(time_data$df), duration = 1500) }) output$chart2 <- renderBillboarder({ df <- data.frame( x = Sys.time() - 1:20 * 2, y = round(rnorm(20) * 10) ) billboarder() %>% bb_linechart(data = df) %>% bb_x_axis(tick = list(format = "%H:%M", fit = FALSE)) }) observe({ invalidateLater(2000) billboarderProxy("chart2") %>% bb_proxy_flow(json = list( x = list(format(Sys.time())), y = list(round(rnorm(1) * 10)) ), data = list(x = "x")) }) } shinyApp(ui, server) }
Highlights specified targets and fade out the others.
bb_proxy_focus(proxy, ids = NULL) bb_proxy_defocus(proxy, ids = NULL)
bb_proxy_focus(proxy, ids = NULL) bb_proxy_defocus(proxy, ids = NULL)
proxy |
A |
ids |
Data ids (names) to be highlighted, if |
A billboardProxy
htmlwidget
object.
bb_defocus
is the opposite of bb_focus
if (interactive()) { library("shiny") library("billboarder") ui <- fluidPage( tags$h1("Proxy method to highlight data"), checkboxGroupInput( inputId = "focus", label = "Focus", choices = c("setosa", "versicolor", "virginica"), inline = TRUE ), billboarderOutput(outputId = "bb") ) server <- function(input, output, session) { output$bb <- renderBillboarder({ billboarder() %>% bb_scatterplot( data = iris, x = "Sepal.Length", y = "Sepal.Width", group = "Species" ) %>% bb_axis(x = list(tick = list(fit = FALSE))) %>% bb_point(r = 8) }) observeEvent(input$focus, { billboarderProxy("bb") %>% bb_proxy_focus(input$focus) }, ignoreNULL = FALSE) } shinyApp(ui = ui, server = server) }
if (interactive()) { library("shiny") library("billboarder") ui <- fluidPage( tags$h1("Proxy method to highlight data"), checkboxGroupInput( inputId = "focus", label = "Focus", choices = c("setosa", "versicolor", "virginica"), inline = TRUE ), billboarderOutput(outputId = "bb") ) server <- function(input, output, session) { output$bb <- renderBillboarder({ billboarder() %>% bb_scatterplot( data = iris, x = "Sepal.Length", y = "Sepal.Width", group = "Species" ) %>% bb_axis(x = list(tick = list(fit = FALSE))) %>% bb_point(r = 8) }) observeEvent(input$focus, { billboarderProxy("bb") %>% bb_proxy_focus(input$focus) }, ignoreNULL = FALSE) } shinyApp(ui = ui, server = server) }
Update chart groups with proxy
bb_proxy_groups(proxy, ...)
bb_proxy_groups(proxy, ...)
proxy |
A |
... |
Vector(s) with id of the series, e.g. the name of variables. |
A billboardProxy
htmlwidget
object.
Hide method with proxy
bb_proxy_hide(proxy, targetIdsValue, options = NULL)
bb_proxy_hide(proxy, targetIdsValue, options = NULL)
proxy |
A |
targetIdsValue |
Name of series to hide. |
options |
Additional options. |
A billboardProxy
htmlwidget
object.
Show or hide legend with proxy
bb_proxy_legend(proxy, what = c("show", "hide"), targetIds = NULL)
bb_proxy_legend(proxy, what = c("show", "hide"), targetIds = NULL)
proxy |
A |
what |
|
targetIds |
Series ids to show/hide, if |
A billboardProxy
htmlwidget
object.
if (interactive()) { library("shiny") data("prod_par_filiere") ui <- fluidPage( tags$h2("Show or hide legend with Proxy"), fluidRow( column( width = 3, checkboxInput( inputId = "show_legend", label = "Show legend", value = TRUE ), checkboxGroupInput( inputId = "item_show", label = "Item to show in legend", choices = c("Hydraulic" = "prod_hydraulique", "Wind" = "prod_eolien", "Solar" = "prod_solaire"), selected = c("prod_hydraulique", "prod_eolien", "prod_solaire") ) ), column( width = 9, billboarderOutput(outputId = "mybb") ) ) ) server <- function(input, output, session) { output$mybb <- renderBillboarder({ billboarder() %>% bb_barchart( data = prod_par_filiere[, c( "annee", "prod_hydraulique", "prod_eolien", "prod_solaire" )], stacked = TRUE ) %>% bb_data( names = list(prod_hydraulique = "Hydraulic", prod_eolien = "Wind", prod_solaire = "Solar"), labels = TRUE ) %>% bb_colors_manual( "prod_eolien" = "#41AB5D", "prod_hydraulique" = "#4292C6", "prod_solaire" = "#FEB24C" ) %>% bb_y_grid(show = TRUE) %>% bb_y_axis( tick = list(format = suffix("TWh")), label = list(text = "production (in terawatt-hours)", position = "outer-top") ) %>% bb_legend(position = "right") %>% bb_labs( title = "Renewable energy production", caption = "Data source: RTE (https://opendata.rte-france.com)" ) }) observe({ if (input$show_legend) { billboarderProxy("mybb") %>% bb_proxy_legend(what = "show") } else { billboarderProxy("mybb") %>% bb_proxy_legend(what = "hide") } }) observe({ lapply( X = c("prod_hydraulique", "prod_eolien", "prod_solaire"), FUN = function(x) { if (x %in% input$item_show) { billboarderProxy("mybb") %>% bb_proxy_legend(what = "show", targetIds = x) } else { billboarderProxy("mybb") %>% bb_proxy_legend(what = "hide", targetIds = x) } } ) }) } shinyApp(ui = ui, server = server) }
if (interactive()) { library("shiny") data("prod_par_filiere") ui <- fluidPage( tags$h2("Show or hide legend with Proxy"), fluidRow( column( width = 3, checkboxInput( inputId = "show_legend", label = "Show legend", value = TRUE ), checkboxGroupInput( inputId = "item_show", label = "Item to show in legend", choices = c("Hydraulic" = "prod_hydraulique", "Wind" = "prod_eolien", "Solar" = "prod_solaire"), selected = c("prod_hydraulique", "prod_eolien", "prod_solaire") ) ), column( width = 9, billboarderOutput(outputId = "mybb") ) ) ) server <- function(input, output, session) { output$mybb <- renderBillboarder({ billboarder() %>% bb_barchart( data = prod_par_filiere[, c( "annee", "prod_hydraulique", "prod_eolien", "prod_solaire" )], stacked = TRUE ) %>% bb_data( names = list(prod_hydraulique = "Hydraulic", prod_eolien = "Wind", prod_solaire = "Solar"), labels = TRUE ) %>% bb_colors_manual( "prod_eolien" = "#41AB5D", "prod_hydraulique" = "#4292C6", "prod_solaire" = "#FEB24C" ) %>% bb_y_grid(show = TRUE) %>% bb_y_axis( tick = list(format = suffix("TWh")), label = list(text = "production (in terawatt-hours)", position = "outer-top") ) %>% bb_legend(position = "right") %>% bb_labs( title = "Renewable energy production", caption = "Data source: RTE (https://opendata.rte-france.com)" ) }) observe({ if (input$show_legend) { billboarderProxy("mybb") %>% bb_proxy_legend(what = "show") } else { billboarderProxy("mybb") %>% bb_proxy_legend(what = "hide") } }) observe({ lapply( X = c("prod_hydraulique", "prod_eolien", "prod_solaire"), FUN = function(x) { if (x %in% input$item_show) { billboarderProxy("mybb") %>% bb_proxy_legend(what = "show", targetIds = x) } else { billboarderProxy("mybb") %>% bb_proxy_legend(what = "hide", targetIds = x) } } ) }) } shinyApp(ui = ui, server = server) }
Show method with proxy
bb_proxy_show(proxy, targetIdsValue, options = NULL)
bb_proxy_show(proxy, targetIdsValue, options = NULL)
proxy |
A |
targetIdsValue |
Name of series to show. |
options |
Additional options. |
A billboardProxy
htmlwidget
object.
Show or hide tooltip with proxy
bb_proxy_tooltip(proxy, what = c("show", "hide"), x = NULL, index = NULL, ...)
bb_proxy_tooltip(proxy, what = c("show", "hide"), x = NULL, index = NULL, ...)
proxy |
A |
what |
|
x |
x value on which the tooltip must appear. |
index |
Index on the x-axis on which the tooltip must appear. |
... |
Additional arguments passed to method. |
A billboardProxy
htmlwidget
object.
Update chart type with proxy
bb_proxy_transform(proxy, type, targetIds = NULL)
bb_proxy_transform(proxy, type, targetIds = NULL)
proxy |
A |
type |
Specify the type to be transformed. |
targetIds |
Specify targets to be transformed. If not given, all targets will be the candidate. |
A billboardProxy
htmlwidget
object.
Update x values with proxy
bb_proxy_xs(proxy, xs)
bb_proxy_xs(proxy, xs)
proxy |
A |
xs |
Named list of vector(s) used for x values. |
A billboardProxy
htmlwidget
object.
Radar property for a Billboard.js chart
bb_radar(bb, ...)
bb_radar(bb, ...)
bb |
A |
... |
See https://naver.github.io/billboard.js/release/latest/doc/Options.html#.radar |
A billboard
htmlwidget
object.
library("billboarder") data("avengers") # number of levels billboarder() %>% bb_radarchart( data = avengers, mapping = bbaes(x = axis, y = value, group = group) ) %>% bb_radar(level = list(depth = 4)) # hide levels billboarder() %>% bb_radarchart( data = avengers, mapping = bbaes(x = axis, y = value, group = group) ) %>% bb_radar(level = list(show = FALSE)) # max value on axis billboarder() %>% bb_radarchart( data = avengers, mapping = bbaes(x = axis, y = value, group = group) ) %>% bb_radar(axis = list(max = 10))
library("billboarder") data("avengers") # number of levels billboarder() %>% bb_radarchart( data = avengers, mapping = bbaes(x = axis, y = value, group = group) ) %>% bb_radar(level = list(depth = 4)) # hide levels billboarder() %>% bb_radarchart( data = avengers, mapping = bbaes(x = axis, y = value, group = group) ) %>% bb_radar(level = list(show = FALSE)) # max value on axis billboarder() %>% bb_radarchart( data = avengers, mapping = bbaes(x = axis, y = value, group = group) ) %>% bb_radar(axis = list(max = 10))
Helper for creating a radar chart
bb_radarchart(bb, data, mapping = NULL, ...)
bb_radarchart(bb, data, mapping = NULL, ...)
bb |
A |
data |
A |
mapping |
Mapping of variables on the chart, see |
... |
Arguments passed to |
A billboard
htmlwidget
object.
library("billboarder") # data about Avengers data("avengers_wide") # if not specified, first column is used as x-axis, # all others are used on y-axis billboarder() %>% bb_radarchart(data = avengers_wide) # specify explicitly which column to use with mapping billboarder() %>% bb_radarchart( data = avengers_wide, mapping = bbaes(x = axis, y = `Captain America`) ) # with data in "long" format you can use "group" aesthetics data("avengers") billboarder() %>% bb_radarchart( data = avengers, mapping = bbaes(x = axis, y = value, group = group) )
library("billboarder") # data about Avengers data("avengers_wide") # if not specified, first column is used as x-axis, # all others are used on y-axis billboarder() %>% bb_radarchart(data = avengers_wide) # specify explicitly which column to use with mapping billboarder() %>% bb_radarchart( data = avengers_wide, mapping = bbaes(x = axis, y = `Captain America`) ) # with data in "long" format you can use "group" aesthetics data("avengers") billboarder() %>% bb_radarchart( data = avengers, mapping = bbaes(x = axis, y = value, group = group) )
Add a shading effect to the background of the chart, to highlight a period for example.
bb_regions(bb, ...)
bb_regions(bb, ...)
bb |
A |
... |
See https://naver.github.io/billboard.js/release/latest/doc/Options.html#.regions |
A billboard
htmlwidget
object.
This function can be used with billboarderProxy
in shiny application.
#' With a categorical X-axis dat <- data.frame( month = month.abb, AirPassengers = tail(AirPassengers, 12) ) # Highlight Jun/Jul/Aug billboarder() %>% bb_linechart(data = dat, x = "month") %>% bb_x_axis(type = "category") %>% bb_regions( list(start = 4.5, end = 7.5) #' jan = 0 ) # With a barchart billboarder() %>% bb_barchart(data = dat) %>% bb_regions( list(start = 1.5, end = 2.5, class = "custom"), list(start = 8, end = 10, class = "foo") ) %>% bb_add_style(region = list(custom = "fill: red;", foo = "fill: #'009246;")) # With Date X-axis library("stats") dat <- data.frame( date = seq.Date(from = Sys.Date(), by = "day", length.out = 365), var = density(rexp(n = 1000), n = 365)$y ) billboarder() %>% bb_linechart(data = dat) %>% bb_x_axis(tick = list(fit = FALSE)) %>% bb_y_axis(min = 0, padding = 0) %>% bb_regions( list(start = format(Sys.Date() + 30), end = format(Sys.Date() + 120)) ) # With POSIXct X-axis dat <- data.frame( time = seq.POSIXt(from = Sys.time(), by = "min", length.out = 60), var = round(sort(rnorm(60)), 2) ) billboarder() %>% bb_linechart(data = dat) %>% bb_x_axis(tick = list(format = "%H:%M", fit = FALSE)) %>% bb_regions( list(start = format(dat$time[15]), end = format(dat$time[30])) )
#' With a categorical X-axis dat <- data.frame( month = month.abb, AirPassengers = tail(AirPassengers, 12) ) # Highlight Jun/Jul/Aug billboarder() %>% bb_linechart(data = dat, x = "month") %>% bb_x_axis(type = "category") %>% bb_regions( list(start = 4.5, end = 7.5) #' jan = 0 ) # With a barchart billboarder() %>% bb_barchart(data = dat) %>% bb_regions( list(start = 1.5, end = 2.5, class = "custom"), list(start = 8, end = 10, class = "foo") ) %>% bb_add_style(region = list(custom = "fill: red;", foo = "fill: #'009246;")) # With Date X-axis library("stats") dat <- data.frame( date = seq.Date(from = Sys.Date(), by = "day", length.out = 365), var = density(rexp(n = 1000), n = 365)$y ) billboarder() %>% bb_linechart(data = dat) %>% bb_x_axis(tick = list(fit = FALSE)) %>% bb_y_axis(min = 0, padding = 0) %>% bb_regions( list(start = format(Sys.Date() + 30), end = format(Sys.Date() + 120)) ) # With POSIXct X-axis dat <- data.frame( time = seq.POSIXt(from = Sys.time(), by = "min", length.out = 60), var = round(sort(rnorm(60)), 2) ) billboarder() %>% bb_linechart(data = dat) %>% bb_x_axis(tick = list(format = "%H:%M", fit = FALSE)) %>% bb_regions( list(start = format(dat$time[15]), end = format(dat$time[30])) )
Render property for a Billboard.js chart
bb_render(bb, ...)
bb_render(bb, ...)
bb |
A |
... |
See https://naver.github.io/billboard.js/release/latest/doc/Options.html#.render for possible options. |
A billboard
htmlwidget
object.
Helper for creating a scatter chart
bb_scatterplot(bb, data, mapping = NULL, ..., point_opacity = NULL)
bb_scatterplot(bb, data, mapping = NULL, ..., point_opacity = NULL)
bb |
A |
data |
A |
mapping |
Mapping of variables on the chart, see |
... |
Alternative mapping, you can specify |
point_opacity |
Opacity for points, value between |
A billboard
htmlwidget
object.
This function can be used with billboarderProxy
in shiny application.
# Use first and second variable by default billboarder() %>% bb_scatterplot(data = iris) # Explicit mapping billboarder() %>% bb_scatterplot( data = iris, mapping = bbaes(Petal.Length, Petal.Width) ) %>% bb_x_axis(tick = list(fit = FALSE)) # Grouping variable billboarder() %>% bb_scatterplot( data = iris, mapping = bbaes(Sepal.Length, Sepal.Width, group = Species) ) # Size variable billboarder() %>% bb_scatterplot( data = iris, mapping = bbaes( Sepal.Length, Sepal.Width, group = Species, size = Petal.Width ) ) %>% bb_x_axis(tick = list(fit = FALSE))
# Use first and second variable by default billboarder() %>% bb_scatterplot(data = iris) # Explicit mapping billboarder() %>% bb_scatterplot( data = iris, mapping = bbaes(Petal.Length, Petal.Width) ) %>% bb_x_axis(tick = list(fit = FALSE)) # Grouping variable billboarder() %>% bb_scatterplot( data = iris, mapping = bbaes(Sepal.Length, Sepal.Width, group = Species) ) # Size variable billboarder() %>% bb_scatterplot( data = iris, mapping = bbaes( Sepal.Length, Sepal.Width, group = Species, size = Petal.Width ) ) %>% bb_x_axis(tick = list(fit = FALSE))
Spline property for a Billboard.js chart
bb_spline(bb, ...)
bb_spline(bb, ...)
bb |
A |
... |
See https://naver.github.io/billboard.js/release/latest/doc/Options.html#.spline |
A billboard
htmlwidget
object.
Create a subchart allowing to zoom and navigate on the chart.
bb_subchart(bb, ...)
bb_subchart(bb, ...)
bb |
A |
... |
See https://naver.github.io/billboard.js/release/latest/doc/Options.html#.subchart |
A billboard
htmlwidget
object.
data("equilibre_mensuel") billboarder() %>% bb_linechart(data = equilibre_mensuel[, c("date", "production")], type = "spline") %>% bb_subchart(show = TRUE)
data("equilibre_mensuel") billboarder() %>% bb_linechart(data = equilibre_mensuel[, c("date", "production")], type = "spline") %>% bb_subchart(show = TRUE)
SVG property for a Billboard.js chart
bb_svg(bb, ...)
bb_svg(bb, ...)
bb |
A |
... |
See https://naver.github.io/billboard.js/release/latest/doc/Options.html#.svg |
A billboard
htmlwidget
object.
Add title to Billboard.js chart
bb_title(bb, text = NULL, padding = NULL, position = "top-center", ...)
bb_title(bb, text = NULL, padding = NULL, position = "top-center", ...)
bb |
A |
text |
The chart title. |
padding |
A named list with |
position |
A string specifying the position of the title. |
... |
Additional arguments. |
A billboard
htmlwidget
object.
billboarder() %>% bb_barchart(data = table(sample(letters, 100, TRUE))) %>% bb_title(text = "Random letters", position = "center")
billboarder() %>% bb_barchart(data = table(sample(letters, 100, TRUE))) %>% bb_title(text = "Random letters", position = "center")
Tooltip property for a Billboard.js chart
bb_tooltip(bb, ...)
bb_tooltip(bb, ...)
bb |
A |
... |
See https://naver.github.io/billboard.js/release/latest/doc/Options.html#.tooltip |
A billboard
htmlwidget
object.
# Format tooltip billboarder() %>% bb_scatterplot(data = iris, x = "Sepal.Length", y = "Sepal.Width", group = "Species") %>% bb_tooltip( format = list( # skip the title in tooltip title = htmlwidgets::JS("function() {return undefined;}"), name = htmlwidgets::JS("function(name, ratio, id, index) {return '';}"), value = htmlwidgets::JS("function(value, ratio, id, index) {return id;}") ) )
# Format tooltip billboarder() %>% bb_scatterplot(data = iris, x = "Sepal.Length", y = "Sepal.Width", group = "Species") %>% bb_tooltip( format = list( # skip the title in tooltip title = htmlwidgets::JS("function() {return undefined;}"), name = htmlwidgets::JS("function(name, ratio, id, index) {return '';}"), value = htmlwidgets::JS("function(value, ratio, id, index) {return id;}") ) )
Transition property for a Billboard.js chart
bb_transition(bb, ...)
bb_transition(bb, ...)
bb |
A |
... |
See https://naver.github.io/billboard.js/release/latest/doc/Options.html#.transition |
A billboard
htmlwidget
object.
Treemap property for a Billboard.js chart
bb_treemap(bb, ...)
bb_treemap(bb, ...)
bb |
A |
... |
See https://naver.github.io/billboard.js/release/latest/doc/Options.html#.treemap |
A billboard
htmlwidget
object.
library("billboarder") data("mpg", package = "ggplot2") billboarder() %>% bb_treemapchart(mpg[, 1]) %>% bb_treemap(label = list(show = TRUE, threshold = 0.03))%>% bb_data( labels = list(colors = "#FFF") )
library("billboarder") data("mpg", package = "ggplot2") billboarder() %>% bb_treemapchart(mpg[, 1]) %>% bb_treemap(label = list(show = TRUE, threshold = 0.03))%>% bb_data( labels = list(colors = "#FFF") )
Helper for creating a treemap chart
bb_treemapchart(bb, data, mapping = NULL, ...)
bb_treemapchart(bb, data, mapping = NULL, ...)
bb |
A |
data |
A |
mapping |
Mapping of variables on the chart, see |
... |
Arguments passed to |
A billboard
htmlwidget
object.
library("billboarder") data("mpg", package = "ggplot2") billboarder() %>% bb_treemapchart(mpg[, 1]) billboarder() %>% bb_treemapchart( data = mpg, mapping = aes(x = manufacturer), label = list(show = TRUE, threshold = 0.3) ) %>% bb_data( labels = list(colors = "#FFF") )
library("billboarder") data("mpg", package = "ggplot2") billboarder() %>% bb_treemapchart(mpg[, 1]) billboarder() %>% bb_treemapchart( data = mpg, mapping = aes(x = manufacturer), label = list(show = TRUE, threshold = 0.3) ) %>% bb_data( labels = list(colors = "#FFF") )
Unload data to the chart with proxy
bb_unload(proxy, ids = NULL)
bb_unload(proxy, ids = NULL)
proxy |
A |
ids |
Data ids to unload. |
A billboardProxy
htmlwidget
object.
Zoom property for a Billboard.js chart
bb_zoom(bb, ...)
bb_zoom(bb, ...)
bb |
A |
... |
See https://naver.github.io/billboard.js/release/latest/doc/Options.html#.zoom |
A billboard
htmlwidget
object.
# data data("equilibre_mensuel") # line chart billboarder() %>% bb_linechart( data = equilibre_mensuel[, c("date", "consommation", "production")], type = "spline" ) %>% bb_x_axis(tick = list(format = "%Y-%m", fit = FALSE)) %>% bb_zoom(enabled = TRUE)
# data data("equilibre_mensuel") # line chart billboarder() %>% bb_linechart( data = equilibre_mensuel[, c("date", "consommation", "production")], type = "spline" ) %>% bb_x_axis(tick = list(format = "%Y-%m", fit = FALSE)) %>% bb_zoom(enabled = TRUE)
Map variables on the chart
bb_aes(bb, ...) bb_aes_string(bb, ...) bbaes(...) bbaes_string(...)
bb_aes(bb, ...) bb_aes_string(bb, ...) bbaes(...) bbaes_string(...)
bb |
A |
... |
Mapping parameters, such as |
A billboard
htmlwidget
object.
bb_aes
is intended to use in a "piping" way.
bbaes
is the equivalent to use inside a helper function
such as bb_barchart
, bb_scatterplot
...
## Not run: dat <- as.data.frame(table(sample(letters[1:5], 100, TRUE))) billboarder(data = dat) %>% bb_aes(x = Var1, y = Freq) %>% bb_barchart() tab <- table(sample(letters[1:5], 100, TRUE), sample(LETTERS[1:5], 100, TRUE)) dat_group <- as.data.frame(tab) billboarder(data = dat_group) %>% bb_aes(x = Var1, y = Freq, group = "Var2") %>% bb_barchart() ## End(Not run)
## Not run: dat <- as.data.frame(table(sample(letters[1:5], 100, TRUE))) billboarder(data = dat) %>% bb_aes(x = Var1, y = Freq) %>% bb_barchart() tab <- table(sample(letters[1:5], 100, TRUE), sample(LETTERS[1:5], 100, TRUE)) dat_group <- as.data.frame(tab) billboarder(data = dat_group) %>% bb_aes(x = Var1, y = Freq, group = "Var2") %>% bb_barchart() ## End(Not run)
Set theme and default colors for Billboard charts
set_theme(name = c("billboard", "insight", "graph", "datalab", "modern")) set_color_palette(colors)
set_theme(name = c("billboard", "insight", "graph", "datalab", "modern")) set_color_palette(colors)
name |
Name of the theme, possible values are : '"billboard"', '"insight"', '"graph"', '"datalab"', '"modern"'. |
colors |
Vector of colors to use as default. |
You can only use one theme and palette at a time (in Shiny applications or Markdown documents).
library("billboarder") set_theme("insight") data("prod_par_filiere") billboarder() %>% bb_barchart( data = prod_par_filiere[, c("annee", "prod_hydraulique", "prod_eolien", "prod_solaire")] ) %>% bb_data( names = list(prod_hydraulique = "Hydraulic", prod_eolien = "Wind", prod_solaire = "Solar") ) %>% bb_y_grid(show = TRUE) %>% bb_y_axis(tick = list(format = suffix("TWh")), label = list(text = "production (in terawatt-hours)", position = "outer-top")) %>% bb_legend(position = "inset", inset = list(anchor = "top-right")) %>% bb_labs(title = "Renewable energy production", caption = "Data source: RTE (https://opendata.rte-france.com)")
library("billboarder") set_theme("insight") data("prod_par_filiere") billboarder() %>% bb_barchart( data = prod_par_filiere[, c("annee", "prod_hydraulique", "prod_eolien", "prod_solaire")] ) %>% bb_data( names = list(prod_hydraulique = "Hydraulic", prod_eolien = "Wind", prod_solaire = "Solar") ) %>% bb_y_grid(show = TRUE) %>% bb_y_axis(tick = list(format = suffix("TWh")), label = list(text = "production (in terawatt-hours)", position = "outer-top")) %>% bb_legend(position = "inset", inset = list(anchor = "top-right")) %>% bb_labs(title = "Renewable energy production", caption = "Data source: RTE (https://opendata.rte-france.com)")
Create an interactive visualization with Javascript library Billboard.js
billboarder( bb_opts = list(), data = NULL, width = NULL, height = NULL, elementId = NULL )
billboarder( bb_opts = list(), data = NULL, width = NULL, height = NULL, elementId = NULL )
bb_opts |
A |
data |
A |
width |
A numeric input in pixels. |
height |
A numeric input in pixels. |
elementId |
Use an explicit element ID for the widget. |
The following functions are imported and then re-exported from the billboarder package to avoid listing the magrittr as Depends of billboarder
Output and render functions for using billboarder within Shiny applications and interactive Rmd documents.
billboarderOutput(outputId, width = "100%", height = "400px") renderBillboarder(expr, env = parent.frame(), quoted = FALSE) billboarderProxy( shinyId, data = NULL, session = shiny::getDefaultReactiveDomain() )
billboarderOutput(outputId, width = "100%", height = "400px") renderBillboarder(expr, env = parent.frame(), quoted = FALSE) billboarderProxy( shinyId, data = NULL, session = shiny::getDefaultReactiveDomain() )
outputId |
output variable to read from |
width , height
|
Must be a valid CSS unit (like |
expr |
An expression that generates a billboarder |
env |
The environment in which to evaluate |
quoted |
Is |
shinyId |
single-element character vector indicating the output ID of the chart to modify (if invoked from a Shiny module, the namespace will be added automatically) |
data |
A |
session |
the Shiny session object to which the chart belongs; usually the default value will suffice |
if (interactive()) { library(shiny) ui <- fluidPage( tags$h2("Include billboard charts in Shiny"), fluidRow( column( width = 6, billboarderOutput("mybb1"), tags$p("Click on a bar to get the value:"), verbatimTextOutput("res_click") ), column( width = 6, billboarderOutput("mybb2") ) ) ) server <- function(input, output, session) { output$mybb1 <- renderBillboarder({ dat <- data.frame( label = paste("Label", 1:5), value = sample.int(100, 5) ) billboarder() %>% bb_barchart( data = dat, mapping = bbaes(label, value), rotated = TRUE ) }) output$res_click <- renderPrint({ input$mybb1_click }) output$mybb2 <- renderBillboarder({ data(AirPassengers) air_passengers <- data.frame( date = as.Date(paste( rep(1949:1960, each = 12), rep(1:12, times = 12), "01", sep = "-" )), passengers = AirPassengers ) billboarder() %>% bb_linechart( data = air_passengers, mapping = bbaes(date, passengers), type = "spline" ) %>% bb_x_axis(tick = list(format = "%Y", fit = FALSE)) }) } shinyApp(ui, server) }
if (interactive()) { library(shiny) ui <- fluidPage( tags$h2("Include billboard charts in Shiny"), fluidRow( column( width = 6, billboarderOutput("mybb1"), tags$p("Click on a bar to get the value:"), verbatimTextOutput("res_click") ), column( width = 6, billboarderOutput("mybb2") ) ) ) server <- function(input, output, session) { output$mybb1 <- renderBillboarder({ dat <- data.frame( label = paste("Label", 1:5), value = sample.int(100, 5) ) billboarder() %>% bb_barchart( data = dat, mapping = bbaes(label, value), rotated = TRUE ) }) output$res_click <- renderPrint({ input$mybb1_click }) output$mybb2 <- renderBillboarder({ data(AirPassengers) air_passengers <- data.frame( date = as.Date(paste( rep(1949:1960, each = 12), rep(1:12, times = 12), "01", sep = "-" )), passengers = AirPassengers ) billboarder() %>% bb_linechart( data = air_passengers, mapping = bbaes(date, passengers), type = "spline" ) %>% bb_x_axis(tick = list(format = "%Y", fit = FALSE)) }) } shinyApp(ui, server) }
Average power generation (MW) per 30-minute interval within continental France, aggregated by broad power source. Last update : 2017-07-27.
cdc_prod_filiere
cdc_prod_filiere
A data frame with 48 rows and 11 variables:
Timestamp (POSIXct)
Total production in MW (thermal + hydro + nuclear + solar + wind + bioenergy)
Gas production in MW
Bioenergy production in MW
Hydraulic production in MW
Fossil thermal production in MW
Coal production in MW
Wind production in MW
Solar production in MW
Nuclear production in MW
Oil production in MW
RTE
Monthly history of supply/demand balance (GWh) based on gross consumption, the balance of physical exchanges with foreign countries and offtakes due to pumping. Last update : 2017-07-27.
equilibre_mensuel
equilibre_mensuel
A data frame with 126 rows and 5 variables:
Date
Supply/demand balance (in GWh)
Generation (in GWh)
Pumping for hydraulic generation (in GWh)
Consumption (in GWh)
RTE (https://odre.opendatasoft.com/explore/dataset/equilibre-national-mensuel-prod-conso-brute/)
Shortcut to add a prefix value to axis labels
prefix(x)
prefix(x)
x |
A character of length one. |
suffix
Annual French electricity production (TWh) by branch. Last update : 2017-02-15.
prod_filiere_long
prod_filiere_long
A data frame with 45 rows and 3 variables:
Year
Source of production
Production in TWh
RTE (https://odre.opendatasoft.com/explore/dataset/prod-national-annuel-filiere/)
Annual French electricity production (TWh) by branch. Last update : 2017-02-15.
prod_par_filiere
prod_par_filiere
A data frame with 5 rows and 11 variables:
Year
Total production in TWh (thermal + hydro + nuclear + solar + wind + bioenergy)
Thermal production in TWh (oil + gas + coal)
Hydraulic production in TWh
Bioenergy production in TWh
Wind production in TWh
Coal thermal production in TWh
Solar production in TWh
Gaz thermal production in TWh
Nuclear production in TWh
Oil thermal production in TWh
RTE (https://odre.opendatasoft.com/explore/dataset/prod-national-annuel-filiere/)
Launch an example to demonstrate how to use proxy method from billboarder
in Shiny app.
proxy_example(chart = "gauge")
proxy_example(chart = "gauge")
chart |
Chart type for which to see an example, possible values are |
if (interactive()) { # Titanic passenger proxy_example("bar") # Electricity production by sources and year proxy_example("bar2") # Moving lollipop with mpg dataset from ggplot2 proxy_example("lollipop") # Update a stacked bar chart proxy_example("stacked_bar") # Moving sine and cosine proxy_example("line") # Changing lines and adding ones proxy_example("line2") # Update pie chart proxy_example("pie") # Density with ggplot2 diamonds proxy_example("density") # Histogram with ggplot2 diamonds proxy_example("histogram") }
if (interactive()) { # Titanic passenger proxy_example("bar") # Electricity production by sources and year proxy_example("bar2") # Moving lollipop with mpg dataset from ggplot2 proxy_example("lollipop") # Update a stacked bar chart proxy_example("stacked_bar") # Moving sine and cosine proxy_example("line") # Changing lines and adding ones proxy_example("line2") # Update pie chart proxy_example("pie") # Density with ggplot2 diamonds proxy_example("density") # Histogram with ggplot2 diamonds proxy_example("histogram") }
Shortcut to add a suffix value to axis labels
suffix(x)
suffix(x)
x |
A character of length one. |
prefix