Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stacked Barchart with Customizations #25

Open
rsangole opened this issue Dec 5, 2020 · 0 comments
Open

Stacked Barchart with Customizations #25

rsangole opened this issue Dec 5, 2020 · 0 comments

Comments

@rsangole
Copy link

rsangole commented Dec 5, 2020

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

The customizations I am looking for:

  • stacked bar chart, but no text labels for each sub-stack
  • one label for the total value of the stack
  • custom hover message for category cat_2

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant