Coder Social home page Coder Social logo

dreamrs / billboarder Goto Github PK

View Code? Open in Web Editor NEW
173.0 15.0 21.0 18.42 MB

:bar_chart: R Htmlwidget for billboard.js

Home Page: https://dreamrs.github.io/billboarder/

License: Other

R 94.03% JavaScript 5.95% CSS 0.02%
r data-visualization htmlwidgets

billboarder's Introduction

billboarder

Htmlwidget for billboard.js

version cranlogs Codecov test coverage R-CMD-check

Overview

This package allow you to use billboard.js, a re-usable easy interface JavaScript chart library, based on D3 v4+.

A proxy method is implemented to smoothly update charts in shiny applications, see below for details.

Installation :

Install from CRAN with:

install.packages("billboarder")

Install development version grom GitHub with:

# install.packages("remotes")
remotes::install_github("dreamRs/billboarder")

For interactive examples & documentation, see pkgdown site : https://dreamrs.github.io/billboarder/index.html

Bar / column charts

Simple bar chart :

library("billboarder")

# data
data("prod_par_filiere")

# a bar chart !
billboarder() %>%
  bb_barchart(data = prod_par_filiere[, c("annee", "prod_hydraulique")], color = "#102246") %>%
  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(show = FALSE) %>% 
  bb_labs(title = "French hydraulic production",
          caption = "Data source: RTE (https://opendata.rte-france.com)")

Multiple categories bar chart :

library("billboarder")

# data
data("prod_par_filiere")

# dodge bar chart !
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)")

Stacked bar charts :

library("billboarder")

# data
data("prod_par_filiere")

# stacked bar chart !
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)")

Scatter plot

Classic :

library(billboarder)
library(palmerpenguins)
billboarder() %>% 
  bb_scatterplot(data = penguins, x = "bill_length_mm", y = "flipper_length_mm", group = "species") %>% 
  bb_axis(x = list(tick = list(fit = FALSE))) %>% 
  bb_point(r = 8)

You can make a bubble chart using size aes :

billboarder() %>% 
  bb_scatterplot(
    data = penguins, 
    mapping = bbaes(
      bill_length_mm, flipper_length_mm, group = species,
      size = scales::rescale(body_mass_g, c(1, 100))
    )
  ) %>% 
  bb_bubble(maxR = 25) %>% 
  bb_x_axis(tick = list(fit = FALSE))

Pie / Donut charts

library("billboarder")

# data
data("prod_par_filiere")
nuclear2016 <- data.frame(
  sources = c("Nuclear", "Other"),
  production = c(
    prod_par_filiere$prod_nucleaire[prod_par_filiere$annee == "2016"],
    prod_par_filiere$prod_total[prod_par_filiere$annee == "2016"] -
      prod_par_filiere$prod_nucleaire[prod_par_filiere$annee == "2016"]
  )
)

# pie chart !
billboarder() %>% 
  bb_piechart(data = nuclear2016) %>% 
  bb_labs(title = "Share of nuclear power in France in 2016",
          caption = "Data source: RTE (https://opendata.rte-france.com)")

Lines charts

Time serie with Date (and a subchart)

library("billboarder")

# 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_x_grid(show = TRUE) %>% 
  bb_y_grid(show = TRUE) %>% 
  bb_colors_manual("consommation" = "firebrick", "production" = "forestgreen") %>% 
  bb_legend(position = "right") %>% 
  bb_subchart(show = TRUE, size = list(height = 30)) %>% 
  bb_labs(title = "Monthly electricity consumption and production in France (2007 - 2017)",
          y = "In megawatt (MW)",
          caption = "Data source: RTE (https://opendata.rte-france.com)")

Zoom by dragging

billboarder() %>% 
  bb_linechart(
    data = equilibre_mensuel[, c("date", "consommation", "production")], 
    type = "spline"
  ) %>% 
  bb_x_axis(tick = list(format = "%Y-%m", fit = FALSE)) %>% 
  bb_x_grid(show = TRUE) %>% 
  bb_y_grid(show = TRUE) %>% 
  bb_colors_manual("consommation" = "firebrick", "production" = "forestgreen") %>% 
  bb_legend(position = "right") %>% 
  bb_zoom(
    enabled = TRUE,
    type = "drag",
    resetButton = list(text = "Unzoom")
  ) %>% 
  bb_labs(title = "Monthly electricity consumption and production in France (2007 - 2017)",
          y = "In megawatt (MW)",
          caption = "Data source: RTE (https://opendata.rte-france.com)")

Time serie with POSIXct (and regions)

library("billboarder")

# data
data("cdc_prod_filiere")

# Retrieve sunrise and and sunset data with `suncalc`
library("suncalc")
sun <- getSunlightTimes(date = as.Date("2017-06-12"), lat = 48.86, lon = 2.34, tz = "CET")


# line chart
billboarder() %>% 
  bb_linechart(data = cdc_prod_filiere[, c("date_heure", "prod_solaire")]) %>% 
  bb_x_axis(tick = list(format = "%H:%M", fit = FALSE)) %>% 
  bb_y_axis(min = 0, padding = 0) %>% 
  bb_regions(
    list(
      start = as.numeric(cdc_prod_filiere$date_heure[1]) * 1000,
      end = as.numeric(sun$sunrise)*1000
    ), 
    list(
      start = as.numeric(sun$sunset) * 1000, 
      end = as.numeric(cdc_prod_filiere$date_heure[48]) * 1000
    )
  ) %>% 
  bb_x_grid(
    lines = list(
      list(value = as.numeric(sun$sunrise)*1000, text = "sunrise"),
      list(value = as.numeric(sun$sunset)*1000, text = "sunset")
    )
  ) %>% 
  bb_labs(title = "Solar production (2017-06-12)",
          y = "In megawatt (MW)",
          caption = "Data source: RTE (https://opendata.rte-france.com)")

Stacked area chart

library("billboarder")

# data
data("cdc_prod_filiere")

# area chart !
billboarder() %>% 
  bb_linechart(
    data = cdc_prod_filiere[, c("date_heure", "prod_eolien", "prod_hydraulique", "prod_solaire")], 
    type = "area"
  ) %>% 
  bb_data(
    groups = list(list("prod_eolien", "prod_hydraulique", "prod_solaire")),
    names = list("prod_eolien" = "Wind", "prod_hydraulique" = "Hydraulic", "prod_solaire" = "Solar")
  ) %>% 
  bb_legend(position = "inset", inset = list(anchor = "top-right")) %>% 
  bb_colors_manual(
    "prod_eolien" = "#238443", "prod_hydraulique" = "#225EA8", "prod_solaire" = "#FEB24C", 
    opacity = 0.8
  ) %>% 
  bb_y_axis(min = 0, padding = 0) %>% 
  bb_labs(title = "Renewable energy production (2017-06-12)",
          y = "In megawatt (MW)",
          caption = "Data source: RTE (https://opendata.rte-france.com)")

Line range

# 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)

Histogram & density

billboarder() %>%
  bb_histogram(data = rnorm(1e5), binwidth = 0.25) %>%
  bb_colors_manual()

With a grouping variable :

# Generate some data
dat <- data.frame(
  sample = c(rnorm(n = 1e4, mean = 1), rnorm(n = 1e4, mean = 2)),
  group = rep(c("A", "B"), each = 1e4), stringsAsFactors = FALSE
)
# Mean by groups
samples_mean <- tapply(dat$sample, dat$group, mean)
# histogram !
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")
    )
  )

Density plot with the same data :

billboarder() %>%
  bb_densityplot(data = dat, x = "sample", group = "group") %>%
  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")
    )
  )

Shiny interaction

Some events will trigger Shiny's inputs in application, such as click. Inputs id associated with billboarder charts use this pattern :

input$CHARTID_EVENT

Look at this example, chart id is mybbchart so you retrieve click with input$mybbchart_click :

library("shiny")
library("billboarder")

# data
data("prod_par_filiere")
prod_par_filiere_l <- reshape2::melt(data = prod_par_filiere)
prod_par_filiere_l <- prod_par_filiere_l[
  with(prod_par_filiere_l, annee == "2016" & variable != "prod_total"), 2:3
]
prod_par_filiere_l <- prod_par_filiere_l[order(prod_par_filiere_l$value), ]


# app
ui <- fluidPage(
  billboarderOutput(outputId = "mybbchart"),
  br(),
  verbatimTextOutput(outputId = "click")
)

server <- function(input, output, session) {
  
  output$mybbchart <- renderBillboarder({
    billboarder() %>%
      bb_barchart(data = prod_par_filiere_l) %>% 
      bb_y_grid(show = TRUE) %>% 
      bb_legend(show = FALSE) %>%
      bb_x_axis(categories = prod_par_filiere_l$variable, fit = FALSE) %>% 
      bb_labs(title = "French electricity generation by branch in 2016",
              y = "production (in terawatt-hours)",
              caption = "Data source: RTE (https://opendata.rte-france.com)")
  })
  
  output$click <- renderPrint({
    cat("# input$mybbchart_click$category", "\n")
    input$mybbchart_click$category
  })
  
}

shinyApp(ui = ui, server = server)

Proxy

You can modify existing charts with function billboarderProxy :

To see examples, run :

library("billboarder")
proxy_example("bar")
proxy_example("line")
proxy_example("pie")
proxy_example("gauge")

Raw API

If you wish, you can build graphs using a list syntax :

data(economics, package = "ggplot2")

# Construct a list in JSON format
params <- list(
  data = list(
    x = "x",
    json = list(
      x = economics$date,
      y = economics$psavert
    ),
    type = "spline"
  ),
  legend = list(show = FALSE),
  point = list(show = FALSE),
  axis = list(
    x = list(
      type = "timeseries",
      tick = list(
        count = 20,
        fit = TRUE,
        format = "%e %b %y"
      )
    ),
    y = list(
      label = list(
        text = "Personal savings rate"
      ),
      tick = list(
        format = htmlwidgets::JS("function(x) {return x + '%';}")
      )
    )
  )
)

# Pass the list as parameter
billboarder(params)

billboarder's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

billboarder's Issues

Treemap with nested categories

Good morning,

Is it possible to create a treemap where we have groups and subgroups? The plotly library allows it. And with this library I have not found any example.

Thank you very much

increase label size

``
image

billboarder() %>%
bb_barchart(
data = explanation_plot_df,
mapping = bbaes(x = feature_desc, y = feature_weight, group = churn_predictor),
rotated = TRUE,
stacked = TRUE
) %>%
bb_colors_manual('Less likely to churn' = 'rgba(63, 182, 24, 0.7)', 'More likely to churn' = 'rgba(255, 0, 57, 0.7)')
})

Customizing the Tooltip / Adding to the Data object

I'd like to customize the tooltip shown when a user hovers over a scatterplot point. To do this, I need to pull data out of the data object passed to format.contents. However, not all of the fields from my data.frame are getting into data. How can I add fields to data, or otherwise get the other columns from the data.frame into the right place?

Here is an example that should illustrate what I mean:

data.frame(
  x = rnorm(200), 
  y = rnorm(200), 
  group = sample(letters[1:3], size=200, replace=T), 
  label = sample(letters[4:26], size=200, replace=T) 
) %>%
  billboarder(data=.) %>%
  bb_aes(x = x, y = y, group=group, label=label) %>%
  bb_scatterplot() %>%
  bb_tooltip(grouped=FALSE, 
             contents = htmlwidgets::JS(
               "function(data, titleFormat, valueFormat, color) {console.log(data);return `<table><tr><td>${data[0].label}</td></tr><tr><td>${data[0].x}</td></tr><tr><td>${data[0].value}</td></tr></table>`;}"
             ))

As of now, the labels are all undefined, because data has group for both the id and name fields.

Combination chart (bar + line)

Is it possible to draw combination charts like this one using billboarder? All three ways to map the variables failed. They produced graphs where a redundant bar variable is added showing the x-axis values.

data <- data.frame(
  "index" = 1:6,
  "data4" = c(200, 130, 90, 240, 130, 220),
  "data5" = c(130, 120, 150, 140, 160, 150)
)

billboarder() %>%
  bb_linechart(data[-3]) %>%
  bb_barchart(data[-2])

billboarder(data = data) %>% 
  bb_aes(x = index, y = data4) %>%
  bb_linechart() %>%
  bb_aes(x = index, y = data5) %>% 
  bb_barchart()

billboarder(data = data) %>% 
  bb_linechart(mapping = bbaes(x = index, y = data4)) %>%
  bb_barchart(mapping = bbaes(x = index, y = data5))

Your help is highly appreciated.
Thanks!
Anja

using different line type

Hi,
I would like to ask two questions:

  • How can we use two different line type for multiline graph. I want to use dashed line for one data, and normal line for other one.
  • I also want to use different width for each line but I could not find an example.

I would be so appreciate if you can help about this two issues.

Thank you in advance

Lower part of caption is cut

Dear billboarder team,

thanks for your wonderful R package. I have a minor problem with the display of a chart's caption. The lower part of it is missing. I added bb_opts = list(padding = list(bottom=100)) as argument to the billboarder() function. It works but gets overwritten when the bb_labs() function is called with a caption argument.
How can the bottom margin be enlarged after calling the bb_labs() function? Or is there another way of displaying the caption entirely. Thanks for your help!

Anja

library("billboarder")

# data
data("prod_par_filiere")

# a bar chart !
billboarder() %>%
  bb_barchart(data = prod_par_filiere[, c("annee", "prod_hydraulique")], color = "#102246") %>%
  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(show = FALSE) %>% 
  bb_labs(title = "French hydraulic production",
          caption = "gqpjy: RTE (https://opendata.rte-france.com)")

BarChart/lines with errors

Hello!

Is it possible to make bar charts or lines or dotted lines with error bars (like errorbars in highcharter package)?
Снимок_экрана_060820_041835_PM

Double Click

I have multiple groups in a stack chart, and would like to see one by one. deselecting all the groups to see only one is cumbersome. Is there a double click option like in Plotly to show one series right away?

https://plotly.com/r/bar-charts/

Here if you double click to any legend, it will just filter that group on the chart.

Charts not being loaded using flexdashboard and rmarkdown (>= 1.11)

Hi,

Using this simple example, I am receiving an empty screen upon opening the html document:

---
title: "Untitled"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
```


```{r, echo = FALSE}
library("billboarder")

# data
data("prod_par_filiere")

# a bar chart !
billboarder() %>%
  bb_barchart(data = prod_par_filiere[, c("annee", "prod_hydraulique")], color = "#102246") %>%
  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(show = FALSE) %>% 
  bb_labs(title = "French hydraulic production",
          caption = "Data source: RTE (https://opendata.rte-france.com)")
```

Using Pandoc 2.6:

> xfun::session_info("rmarkdown")
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044), RStudio 1.2.1335

Locale:
  LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
  LC_TIME=English_United States.1252    

Package version:
  base64enc_0.1.3 bslib_0.3.1     digest_0.6.29   evaluate_0.15   fastmap_1.1.0   fs_1.5.2        glue_1.6.2      graphics_4.1.0  grDevices_4.1.0 highr_0.9       htmltools_0.5.2 jquerylib_0.1.4
  jsonlite_1.8.0  knitr_1.39      magrittr_2.0.3  methods_4.1.0   R6_2.5.1        rappdirs_0.3.3  rlang_1.0.2     rmarkdown_2.14  sass_0.4.1      stats_4.1.0     stringi_1.7.6   stringr_1.4.0  
  tinytex_0.39    tools_4.1.0     utils_4.1.0     xfun_0.31       yaml_2.3.5     

Pandoc version: 2.6

The people from rmarkdown were able to find the following:
image

This only happens with rmarkdown versions 1.11 and onwards. Could you please look into this from the JS side of things, to identify what causes this issue to happen?

Possible more information in my original topic: rstudio/rmarkdown#2378

updated billboarder 2.7

Hi,

First of all, i would like to thank for a this great package and your answer for my previous question.
I was using billboarder 2.5 and today updated 2.7.
After updating, all my program started not to work. I cannot see any figure or graph but it does not give any error. It just shows empty figure

What can be the problem?

Thank you in advance

There was no event observed after the triggers happened once

I was trying to create a dashboard that allows users to filter the datatable based on click events on Gauge charts using the billboarder library. However, in my implementation, the dashboard can only observe the events on gauge only once. If I click on the same gauge, it doesn't work anymore.

The following is my sample code.

library(shiny)
library(shinydashboard)
library(billboarder)

sidebar <- dashboardSidebar(
    disable = TRUE,
    collapsed = TRUE,
    sidebarMenu(
        menuItem("Dashboard", tabName="Dashboard", icon=icon("dashboard"))
    )
)

body <- dashboardBody(
    tabItems(
        tabItem(
            tabName = "Dashboard",
            fluidRow(
                box(width = 4, title = "Box 1",
                    billboarderOutput(outputId = "box1", height = "auto")
                ),
                box(width = 4, title = "Box 2",
                    billboarderOutput(outputId = "box2", height = "auto")
                ),
                box(width = 4, title = "Box 3",
                    billboarderOutput(outputId = "box3", height = "auto")
                )
            ),
            fluidRow(
                box(width = 12, title = "output", DTOutput("car_table"))
            )
        )
    )
)

ui <- dashboardPage(
    header = dashboardHeader(), 
    sidebar = sidebar, body = body
)

server <- function(input, output) {
        
    observeEvent(input$box1_click$value, { car_data$data <- subset(mtcars, mpg > 15) })
    observeEvent(input$box2_click$value, { car_data$data <- subset(mtcars, mpg > 25) })
    observeEvent(input$box3_click$value, { car_data$data <- subset(mtcars, mpg > 20) })
    
    car_data <- reactiveValues(data = mtcars)
    
    output$box1 <- renderBillboarder({
        billboarder() %>% 
            bb_gaugechart(value = nrow(subset(mtcars, mpg > 15)), name = "cars") %>% 
            bb_gauge(min = 0, max = nrow(mtcars), units = "items",
                     label = list(format = htmlwidgets::JS("function(value) {return value;}")))
    })
    
    output$box2 <- renderBillboarder({
        billboarder() %>% 
            bb_gaugechart(value = nrow(subset(mtcars, mpg > 25)), name = "cars") %>% 
            bb_gauge(min = 0, max = nrow(mtcars), units = "items", 
                     label = list(format = htmlwidgets::JS("function(value) {return value;}")))
    })
    
    output$box3 <- renderBillboarder({
        billboarder() %>% 
            bb_gaugechart(value = nrow(subset(mtcars, mpg > 20)), name = "cars") %>% 
            bb_gauge(min = 0, max = nrow(mtcars), units = "items",
                     label = list(format = htmlwidgets::JS("function(value) {return value;}")))
    })
    
    output$car_table <- renderDT({
        DT::datatable(car_data$data)
    })
        
}
shinyApp(ui = ui, server = server)

Customize text font

I would like to modify the labels and title of a bb_donut chart. I've tried a couple of ways and no luck.
This was an attempt to change the title font:

output$donut_html<- renderBillboarder({
      detect_info <- data.frame(
        category = c("D", "DNQ", "ND"),
        value = c(5, 10,7)
        )
      
      billboarder() %>%
        bb_donutchart(data = detect_info, title = "Detection info") %>% 
        bb_colors_manual("D" = "#B12839", "DNQ" = "#FCA400", "ND"="#46522A") %>% 
        bb_add_style(donutchart= list(title = "font-family: 'Roboto Condensed';"))

})

Guidance is appreciated.
Cheers,
Maria

Hover Possible?

Like you have in your example for click

output$click <- renderPrint({
    cat("# input$mybbchart_click$category", "\n")
    input$mybbchart_click$category
  })

I couldn't get "hover" to work using something like input$mybbchart_hover$category. Is this something that's possible? Which Shiny events are currently supported?

How can I change the text colors in bb_gaugechart?

I am using billboarder in shiny and as the background is dark I would like to change the color of the gaugechart text (e.g. 24%) to 'white'. How is this possible?

Similarly, in the tooltip the text color is white on white background. How could I change this color?

Best,
Simon

download

How can someone download a chart as a png/jpeg?

Possible bug / conflict with line ranges

Hi, I appreciate this package. I'm trying to make a line range similar to the ones in the bb_linechart examples, but I've run into an issue when I try to set the color of the line and its shaded area. I looked at the HTML the code creates and did these experiments based on the doc example. dat is the same as the data created in the bb_linechart examples:

1. Basic line range, comes out as expected

billboarder(data = dat) %>% 
  bb_linechart(
    mapping = bbaes(x = date, y = y1, ymin = ymin1, ymax = ymax1),
    type = "area-line-range"
  )

Screen Shot 2020-11-24 at 1 49 38 PM

2. Setting color with bb_colors_manual—the decreased opacity for the area is now lost

billboarder(data = dat) %>% 
  bb_linechart(
    mapping = bbaes(x = date, y = y1, ymin = ymin1, ymax = ymax1),
    type = "area-line-range"
  ) %>%
  bb_colors_manual(y1 = "#9b6fa7")

Screen Shot 2020-11-24 at 1 49 50 PM

3. Successful workaround with bb_color palette

billboarder(data = dat) %>% 
  bb_linechart(
    mapping = bbaes(x = date, y = y1, ymin = ymin1, ymax = ymax1),
    type = "area-line-range"
  ) %>%
  bb_color(palette = "#9b6fa7")

Screen Shot 2020-11-24 at 1 50 07 PM

4. Unsuccessful workaround with bb_line and CSS

CSS block:

.area-not-opaque {
  opacity: 0.2;
}
billboarder(data = dat) %>% 
  bb_linechart(
    mapping = bbaes(x = date, y = y1, ymin = ymin1, ymax = ymax1),
    type = "area-line-range"
  ) %>%
  bb_colors_manual(y1 = "#9b6fa7") %>%
  bb_line(classes = c("area-not-opaque"))

In that last example, the custom class doesn't seem to be applied to the line range, but looking in my browser's inspector and the package source, I can't tell where it gets lost. In example 2, I noticed that the lower opacity of the area is overridden with

#htmlwidget-22d6afe4e20b7504cb71 .bb-area {
    opacity: 1 !important;
}

Again, that's something that I'm not sure where it comes from. Another workaround I found is setting the opacity in bb_colors_manual by using e.g. "#9b6fa744", but that makes the line itself also have reduced opacity. For now, the workarounds are fine, I just wanted to point it out as a possible bug or point that could be clarified in the docs. Thanks!

Negative value in bauge / gauge

I tried using negative values in a billboarder::bauge in shiny and somehow it seems like negative values are not displayed - am I doing something wrong or is this a known issue?

Further, when using positive values while having a negative "min" value, only the positive area is rendered, meaning when min = -100 and max = 100 a value of 25 shows only a colored area that equals 25% which is not correct. Again, I might be doing something wrong. If not, is there a fix for this issue?

Update: As far I understand it, this problem seems to be rooted in the billboard.js library itself. So maybe not an issue for this package.

See Code below:

library(shiny)
library(billboarder)

shinyApp(
    
    ui = fluidPage(

        baugeOutput(outputId = "gauge")
        
    ),
    
    server = function(input, output) {
        
        output$gauge <- renderBauge({
            
                            bauge(
                                value = -25, # alternatively use 25 instead of -25
                                min = -100,
                                max = 100,
                                colors = c("#FF0000"),
                                label_format = suffix("")
            )
            
        })
        
    }
    
)

Control label position in bb_radarchart

Hi,

I am trying to position the data labels independently in a radarchart. Since I have only 3 axis (Speed, Durability and Energy), I want to be able to control the x position of the data label in each axis:

  • x = 0 for Speed
  • x = -10 for Durability
  • x = 10 for Energy

The code below exemplifies the issue that I am dealing with.

library("billboarder")
data("avengers")

avengersSub <- avengers %>% 
  filter(group == 'Thor') %>% 
  filter(axis %in% c('Durability','Speed','Energy'))

billboarder() %>%
  bb_radarchart(
    data = avengersSub,
    mapping = bbaes(x = axis, y = value, group = group)
  ) %>%
  bb_radar(level = list(show = FALSE)) %>% 
  bb_data(
    labels = list(position = list(x = -10))
    )

Thank you very much for you help!

Scatterplot with region & custom tooltip

Hello,

I'm wondering if it's possible to create a billboarder equivalent to this plot_ly plot:

library(plotly)

plotly::plot_ly(
  data = mtcars,
  x = ~ mpg,
  y = ~ disp,
  type = "scatter",
  color = ~ as.factor(cyl),
  hoverinfo = "text",
  hovertemplate = ~ glue::glue("<b>Cyl: {grp}</b>
                               mpg: {x}, disp: {y}", grp = cyl, x = mpg, y = disp)
) %>%
  plotly::layout(shapes = list(
    list(
      type = "rect",
      fillcolor = "red",
      line = list(color = "red"),
      opacity = 0.1,
      x0 = "10",
      x1 = "20",
      xref = "x",
      y0 = 30,
      y1 = 350,
      yref = "y"
    )
  ))

image

2 Y axis ?

How would you implement a second Y axis (for values in 3rd column having totally other scale than in 2nd).
Is it natively in R formulas or do we need to pass by API ?

Thx

Tooltip does not appear when linked between charts

Hello DreamRs team,

Thank you for putting together this wonderful package, it is very nice, especially when used in a Shiny app. Whilst trying to learn how to use this package effectively, I came across the example provided by your team showing linked tooltips (located here)

Unfortunately, this does not appear to work, either inside of a shiny app or when just using the defined make_line() function. When using the code as it is now, all of the graphs produced do not have visible tooltips (either in Rstudio 1.2.5.001 viewer or Firefox 71.0, each with R 3.6.1, MS Windows 10).

When editing the code to put a scatterplot on top of the linechart, the vertical line appears when hovering over a point, but not the tooltip:

# on CRAN now (version 0.2.3)
library(billboarder)

# data
data("economics", package = "ggplot2")

# helper fun
make_line <- function(var, title, percent = TRUE) {
  billboarder() %>%
    bb_linechart(data = economics[, c("date", var)]) %>%
    bb_scatterplot(data = economics[, c("date", var)]) %>%
    bb_x_axis(tick = list(format = "%Y-%m", fit = FALSE)) %>%
    bb_y_axis(tick = list(format = if (percent) suffix("%"))) %>%
    bb_legend(show = TRUE) %>%
    bb_x_grid(show = TRUE) %>%
    bb_y_grid(show = TRUE) %>%
    bb_labs(title = title) %>%
    bb_tooltip(linked = list(name = "my-tooltip")) # <--- Id for linking tooltip
}
make_line("psavert", "Personal savings rate", TRUE)
make_line("uempmed", "Number of unemployed", TRUE)
make_line("pce", "Personal consumption expenditures", FALSE)
make_line("pop", "Total population", FALSE)

I also noticed that when doing a simple un-linked bb_linechart() with some example data, the tooltip does not appear either, and I have to put a bb_scatterplot() subsequent to the bb_linechart to make it appear.

I hope this is not too much of a nightmare to resolve, as those tooltips are extremely useful within a Shiny app.

Thanks again for making this package, it is very nice and I eagerly look forward to future updates!

Darren

bb_gauge complete circle

can you help me out how can i get a complete circle gauge chart ?

`billboarder()%>%
bb_gaugechart(num)
Rplot

but i want a full circle gauge chart
`

legend in RMarkdown

I am trying to add billboarder charts in my .Rmd but if it's not located on the landing page the legend isn't loaded correctly. This is a simply example of the problem:

---
title: "Untitled"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
library(billboarder)
library(data.table)
```

Column {.tabset}
-----------------------------------------------------------------------

### Dummy tab


### Chart A

```{r}
billboarder() %>%
  bb_linechart(melt(data.table(rock, keep.rownames = TRUE)[, area := as.numeric(area)], id.vars = "rn", measure.vars = c("area", "peri")), bbaes(rn, value, variable))
```

Stacked Barchart with Customizations

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 ?

Scatterplot in which the grouping variable takes more than 4 different values does not work

Example from Documentation with grouping by cyl works. cyl takes three different values 4 6 and 8

billboarder(data = mtcars) %>% 
  bb_scatterplot(
   mapping = aes(wt, mpg, group = cyl, size = scales::rescale(qsec, to = c(0.2, 7))),
   point_opacity = 1
  ) %>% 
  bb_axis(x = list(tick = list(fit = FALSE))) %>% 
  bb_x_grid(show = TRUE) %>%
  bb_y_grid(show = TRUE)

whereas grouping by carb does not work. carb takes six different values 1 2 3 4 6 and 8

billboarder(data = mtcars) %>% 
    bb_scatterplot(
        mapping = aes(wt, mpg, group = carb, size = scales::rescale(qsec, to = c(0.2, 7))),
        point_opacity = 1
    ) %>% 
    bb_axis(x = list(tick = list(fit = FALSE))) %>% 
    bb_x_grid(show = TRUE) %>%
    bb_y_grid(show = TRUE)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.