Skip to content Skip to sidebar Skip to footer

How To Include Highcharts Motion Plugin For Bubble Plot Using R Wrapper?

Highcharts motion plugin - Requires 3 adjustments to a highchart. The inclusion of the js asset An option object for motion Data to be within sequence arrays. It seems like the

Solution 1:

Luke,

motion.js plugin was added to highcharter. Is in development version (download via devtools), it's need more testing but is it a start.

Please check the example in http://jkunst.com/highcharter/plugins.html#motion:

  highchart() %>% 
    hc_chart(type = "column") %>% 
    hc_yAxis(max = 6, min = 0) %>% 
    hc_add_series(name = "A", data = c(2,3,4), zIndex = -10) %>% 
    hc_add_series(name = "B",
                  data = list(
                    list(sequence = c(1,2,3,4)),
                    list(sequence = c(3,2,1,3)),
                    list(sequence = c(2,5,4,3))
                  )) %>% 
    hc_add_series(name = "C",
                  data = list(
                    list(sequence = c(3,2,1,3)),
                    list(sequence = c(2,5,4,3)),
                    list(sequence = c(1,2,3,4))
                  )) %>% 
    hc_motion(enabled = TRUE,
              labels = 2000:2003,
              series = c(1,2))

If you find any suspicions behavior (aka bugs) please report here: https://github.com/jbkunst/highcharter/issues

Hope it helps


Solution 2:

Have you considered shiny as a temporary solution?

library(shiny)
library(rCharts)
library(dplyr)

server <- shinyServer(function(input, output) {

  output$bubblePlot <- renderChart2({

    # data
    set.seed(1)
    df.SO <- data.frame(date = sample(2005:2016, 21, replace = T)
                        , x = rnorm(21, 10, 4)
                        , y = rnorm(21, 150, 4)
                        , z = rbinom(21, 80, .8)
                        , entities = sample(c("entity1","entity2","entity3"), 21, replace = T))

    # filter data based on selected year
    df.SO.select <- dplyr::filter(df.SO, date == input$date)

    # chart
    h1 <- hPlot(  x     = "x"
                  , y     = "y"
                  , size  = "z"
                  , group = "entities"
                  , data  = df.SO.select
                  , type  = "bubble")
    h1$addParams(dom = "bubbleChart")
    h1$plotOptions(series = list(animation = FALSE))
    h1$xAxis(min = min(df.SO$x), max = max(df.SO$x))
    h1$yAxis(min = min(df.SO$y), max = max(df.SO$y))
    h1

  })

})

ui <- shinyUI(fluidPage(

  # Application title
  titlePanel("Highcharts Bubble Motion Chart"),

  # Sidebar with a slider input for the selected year
  sidebarLayout(
    sidebarPanel(
      sliderInput("date",
                  "Date:",
                  min = 2007,
                  max = 2016,
                  value = 2007,
                  animate = TRUE,
                  sep = "")
    ),

    # Show a bubble plot for the selected year
    mainPanel(
      showOutput("bubblePlot", "highcharts")
    )
  )
))

shinyApp(ui = ui, server = server)

Solution 3:

Surprising I couldn't find any posted examples demonstrating bubble or scatter as the chart type with hc_motion. All examples are either, bar, column, map, pie.

Anyway, after a fair bit of hit & miss, I managed to get scatter plot working doing the following on the sequence. each vector c(1,1) represents x & y coordinates. I'm still trying to get it working with bubble with no luck. Hoping someone might be able to post an code snippet for bubble using the hcaes() format.

Bubble would be handy for motion, as you can then do Gapminder style charts. http://www.gapminder.org/

library(highcharter)

    highchart() %>% 
            hc_chart(type = "scatter") %>% 
            hc_yAxis(max = 6, min = 0) %>% 
            hc_xAxis(max = 6, min = 0) %>%
            hc_add_series(name = "Australia",
                          data = list(
                                  list(sequence = list(c(1,1),c(2,2),c(3,3),c(4,4)))
                          )) %>%
            hc_add_series(name = "United States",
                          data = list(
                                  list(sequence = list(c(0,0),c(3,2),c(4,3),c(4,1)))
                          )) %>%
            hc_add_series(name = "China",
                          data = list(
                                  list(sequence = list(c(3,2),c(2,2),c(1,1),c(2,5)))
                          )) %>% 
            hc_motion(enabled = TRUE,
                      labels = 2000:2003,
                      series = c(0,1,2))

Post a Comment for "How To Include Highcharts Motion Plugin For Bubble Plot Using R Wrapper?"