dreamRs / billboarder

:bar_chart: R Htmlwidget for billboard.js
https://dreamrs.github.io/billboarder/
Other
174 stars 21 forks source link

Stacked Barchart with Customizations #25

Open rsangole opened 3 years ago

rsangole commented 3 years ago

I'm attempting to replace a customized plotly barchart with one using billboarder.

The customizations I am looking for:

Here's a repress for my Plotly chart:

library(plotly)
library(dplyr)
dt <- tibble(
  cat_1 = c("apple", "banana", "apple", "banana"),
  cat_2 = c("store 1", "store 1", "store 2", "store 2"),
  custom_hover_text = c("Hover 1", "Hover 1", "Hover 2", "Hover 2"),
  some_value = c(4, 5, 2, 3)
)
dt <- dt %>%
  dplyr::group_by(cat_2) %>%
  dplyr::mutate(totals_for_the_label = sum(some_value)) %>%
  dplyr::ungroup()
dt

plotly::plot_ly(data = dt) %>%
  plotly::add_bars(
    x = ~ cat_2,
    y = ~ some_value,
    color = ~ cat_1,
    colors = c(`apple` = "#118ab2", `banana` = "#ffd166"),
    hoverinfo = "text",
    hovertext = ~ glue::glue("{custom_hover_text} : {cat_2} is {some_value}")
  ) %>%
  plotly::layout(barmode = "stack") %>%
  plotly::add_text(
    text = ~ totals_for_the_label,
    x = ~ cat_2,
    y = ~ totals_for_the_label,
    textposition = "top middle",
    cliponaxis = FALSE,
    inherit = FALSE,
    hoverinfo = "none",
    showlegend = FALSE
  )

bb

Is this possible with billboarder ?