bhhicharts helps create interactive charts and provides infrastructure for embedding them on the BHHI website.
It can take a single chart or set of related charts and render them on a simple webpage that can then be embedded on the BHHI Drupal site.
You can install bhhicharts from GitHub with:
# install.packages("remotes")
remotes::install_github("ucsf-bhhi/bhhicharts")
bhhicharts relies on the highcharter package to create the charts.
After creating a chart:
library(highcharter)
#> Registered S3 method overwritten by 'quantmod':
#> method from
#> as.zoo.data.frame zoo
scatter_chart = hchart(mtcars, "scatter", hcaes(x = wt, y = mpg, group = cyl)) |>
hc_xAxis(title = list(text = "Weight")) |>
hc_yAxis(title = list(text = "MPG")) |>
hc_legend(title = list(text = "Cylinders"))
It can be rendered in a simple webpage with the BHHI theme and logo applied. The webpage can then be embedded into the BHHI Drupal site.
dir = tempdir()
bhhicharts::create_webpage(
scatter_chart, html_filename = "scatter-chart.html", root_dir = dir
)
bhhicharts can also render a webpage with a chart picker that allows the viewer to choose between multiple charts. This can be useful, for example, to show different visualizations of the data or different demographic groupings.
After creating another chart and putting the charts in a named list:
column_chart = mtcars |>
dplyr::count(cyl, gear) |>
hchart("column", hcaes(x = cyl, y = n, group = gear)) |>
highcharter::hc_plotOptions(column = list(stacking = "normal")) |>
highcharter::hc_xAxis(title = list(text = "Cylinders")) |>
highcharter::hc_yAxis(title = list(text = "Count")) |>
highcharter::hc_legend(title = list(text = "Gears"))
charts = list("Column" = column_chart, "Scatter" = scatter_chart)
The set of charts can be rendered into a webpage:
bhhicharts::create_webpage(
charts, html_filename = "multiple-charts.html", root_dir = dir
)