jbkunst / highcharter

R wrapper for highcharts
http://jkunst.com/highcharter/
Other
719 stars 148 forks source link

Facet grid layout #66

Closed Yang-Tang closed 8 years ago

Yang-Tang commented 8 years ago

Is there any way to show multiple highcharts in facet grid layout?

jbkunst commented 8 years ago

Hi @Yang-Tang ,

Sadly highcharts dont have a facet implementation like taucharts or plotly.

You can implement kind of facet for y axis like http://jkunst.com/highcharter/hchart.html#seasonal-decomposition-of-time-series-by-loess, but there no way to create more x axis.

If you're ok, we can close this issue.

Thanks ;)

haozhu233 commented 8 years ago

Hi @jbkunst,

In fact, I find myself have some difficulties on understanding the underline mechanism when you use hchart() to draw the seasonal decomposition of time series. I want to build some similar facets of time series data but they are not coming from the stl() function. Is there a way to get around that?

Thanks!

jbkunst commented 8 years ago

Hi @haozhu233

Basically, the code from hchart.stl() was based on the candlestick-volume example from highcharts.

You have to work/play with the yAxis to create many xAxis as you need taking care of the topand height arguments:

yAxis: [{
    height: '60%'
}, {
    top: '65%',
    height: '35%',
    offset: 0
}]

Then add each (ts) series to each yaxis.

Hope I was clear :D.

haozhu233 commented 8 years ago

Excellent! @jbkunst , thank you for this short but right-to-the-point instruction! I will play around with it. :)

jbkunst commented 8 years ago

@Yang-Tang , @haozhu233 ,

I'm just implemented a grid function hc_grid to display highchart like faceting. Take a look please: http://rpubs.com/jbkunst/higcharter-grid-test

haozhu233 commented 8 years ago

Excellent! Thanks!! @jbkunst

Yang-Tang commented 8 years ago

That's great! Thanks! @jbkunst

svarn27 commented 8 years ago

How is this incorporated into a shiny app? My test app below.

library(purrr)
library(highcharter)
library(shiny)

data(diamonds, package = "ggplot2")
diamonds <- diamonds[-6]

ui <- fluidPage(highchartOutput('hchart'))

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

output$hchart <- renderHighchart({

map(names(diamonds), function(x){
  diamonds[[x]] %>% 
    hchart(showInLegend = FALSE) %>% 
    hc_add_theme(hc_theme_smpl()) %>% 
    hc_title(text = x) %>% 
    hc_yAxis(title = list(text = ""))
  }) %>% 
  hw_grid(rowheight = 225, ncol = 3) 

})
}

shinyApp(ui=ui,server=server)
jbkunst commented 8 years ago

Hi @svarn27 ,

Use htmlOutput and renderUI works for me.

ui <- fluidPage(htmlOutput('hchart'))

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

  output$hchart <- renderUI({

    map(names(diamonds), function(x){
      diamonds[[x]] %>% 
        hchart(showInLegend = FALSE) %>% 
        hc_add_theme(hc_theme_smpl()) %>% 
        hc_title(text = x) %>% 
        hc_yAxis(title = list(text = ""))
    }) %>% 
      hw_grid(rowheight = 225, ncol = 3) 

  })
}

shinyApp(ui=ui,server=server)
svarn27 commented 8 years ago

OK great, I'll see how I can incorporate it in that fashion. Thanks a ton, this package is amazing. By far the most powerful/flexible I've come across. Your hard work is much appreciated! @jbkunst

charlie86 commented 8 years ago

@jbkunst you are the man!

rfarouni commented 8 years ago

@jbkunst Can the output be directed to RStudio viewer instead of Shiny? Can the multiplot be embedded in a knittr document? Thanks

jbkunst commented 8 years ago

@rfarouni ,

Yep! It's possible.

In console/rstudio viewer you need to use browseable from the htmltools package, see https://github.com/jbkunst/highcharter/blob/master/devscripts/hc_grid2.R

In knitr/rmarkdown documents you just use hw_grid alone. https://github.com/jbkunst/highcharter/blob/master/devscripts/hc_grid.R

Let me if this work for you ;)!

rfarouni commented 8 years ago

Yes it works! Thank you!

mcandar commented 7 years ago

Is it possible to use hw_grid function nested? I want to locate my plots in a layout like this

1 3 3 3
2 3 3 3

two graphs at left and one bigger at right-hand side. Also, I want this pattern to repeat several times as rows. I tried to use hw_grid function in nested forms, but did not make it work.

jbkunst commented 7 years ago

@mcandar

Not sure, but you can try https://github.com/FrancoisGuillem/combineWidgets It supposed to do what you want :sweat_smile:

mcandar commented 7 years ago

@jbkunst thanks! combineWidgets function is also included in manipulateWidget package. They work properly but now I have problems with sizing and adding slider when exporting them as html ... 😄

vinoth4stat commented 6 years ago

@jbkunst....

Below page is not found.. Please help.. https://github.com/jbkunst/highcharter/blob/master/devscripts/hc_grid2.R https://github.com/jbkunst/highcharter/blob/master/devscripts/hc_grid.R

(This is pasted from message "jbkunst commented on Aug 19, 2016" to @rfarouni ....)

Thank You!!!

patarol commented 6 years ago

I've found the link your're looking for @vinoth4stat In this link you can find the mentioned example!

Plus, if you search for hw_grid in the highcharter repo you can find a bunch of examples!

To put side by side highcharter graphs you can do something like that:

htmltools::browsable(hw_grid(h1, h2, ncol = 2, rowheight = 300)) where h1 and h2 are highcharter graphs!