jbkunst / highcharter

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

highcharter 0.5.0 shows numeric labels for category axis #273

Closed Yang-Tang closed 7 years ago

Yang-Tang commented 7 years ago

I want a plot to show character x-axis labels like this Here is my R code:

series_lst <- list(
  list(
    type = 'column',
    data = list(
      list(x = 1, y = 4, name = 'a'),
      list(x = 2, y = 5, name = 'b'),
      list(x = 3, y = 6, name = 'c')
    )
  )
)

highchart() %>% 
  hc_xAxis(type = 'category') %>% 
  hc_add_series_list(series_lst)

The generated plot shows 1, 2, 3 instead of a, b, c as x-axis labels. I tested the same code in highcharter 0.4.0. It gives the correct labels. Here is my sessionInfo:

R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] highcharter_0.5.0

loaded via a namespace (and not attached):
 [1] igraph_1.0.1      Rcpp_0.12.9       magrittr_1.5      mnormt_1.5-5     
 [5] lattice_0.20-34   R6_2.2.0          TTR_0.23-1        stringr_1.1.0    
 [9] plyr_1.8.4        dplyr_0.5.0       xts_0.9-7         tools_3.3.2      
[13] parallel_3.3.2    quantmod_0.4-7    grid_3.3.2        data.table_1.10.0
[17] broom_0.4.1       nlme_3.1-128      psych_1.6.12      DBI_0.5-1        
[21] htmltools_0.3.5   yaml_2.1.14       assertthat_0.1    digest_0.6.11    
[25] tibble_1.2        purrr_0.2.2       reshape2_1.4.2    tidyr_0.6.1      
[29] htmlwidgets_0.8   rlist_0.4.6.1     stringi_1.1.2     jsonlite_1.2     
[33] lubridate_1.6.0   foreign_0.8-67    zoo_1.7-14       
> 
jbkunst commented 7 years ago

Hi @Yang-Tang

Not sure really what change produce this behavior, but if you remove the x will chart what you want.

library(highcharter)

series_lst <- list(
  list(
    type = 'column',
    data = list(
      list(y = 4, name = 'a'),
      list(y = 5, name = 'b'),
      list(y = 6, name = 'c')
    )
  )
)

highchart() %>% 
  hc_xAxis(type = 'category') %>% 
  hc_add_series_list(series_lst)

image

library(highcharter)
#> Highcharts (www.highcharts.com) is a Highsoft software product which is
#> not free for commercial and Governmental use
devtools::session_info()
#> Session info --------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.3.1 (2016-06-21)
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  Spanish_Chile.1252          
#>  tz       America/Santiago            
#>  date     2017-02-21
#> Packages ------------------------------------------------------------------
#>  package     * version    date       source                      
#>  assertthat    0.1        2013-12-06 CRAN (R 3.3.2)              
#>  backports     1.0.4      2016-10-24 CRAN (R 3.3.2)              
#>  broom         0.4.1      2016-06-24 CRAN (R 3.3.1)              
#>  data.table    1.10.0     2016-12-03 CRAN (R 3.3.2)              
#>  DBI           0.5-1      2016-09-10 CRAN (R 3.3.1)              
#>  devtools      1.12.0     2016-06-24 CRAN (R 3.3.2)              
#>  digest        0.6.12     2017-01-27 CRAN (R 3.3.2)              
#>  dplyr         0.5.0      2016-06-24 CRAN (R 3.3.1)              
#>  evaluate      0.10       2016-10-11 CRAN (R 3.3.2)              
#>  foreign       0.8-67     2016-09-13 CRAN (R 3.3.1)              
#>  formatR       1.4        2016-05-09 CRAN (R 3.3.1)              
#>  highcharter * 0.5.0.9999 2017-02-20 local                       
#>  htmltools     0.3.5      2016-03-21 CRAN (R 3.3.1)              
#>  htmlwidgets   0.8        2016-11-09 CRAN (R 3.3.2)              
#>  igraph        1.0.1      2015-06-26 CRAN (R 3.3.0)              
#>  jsonlite      1.2        2016-12-31 CRAN (R 3.3.2)              
#>  knitr         1.15.9     2017-02-08 Github (yihui/knitr@430956f)
#>  lattice       0.20-34    2016-09-06 CRAN (R 3.3.1)              
#>  lubridate     1.6.0      2016-09-13 CRAN (R 3.3.1)              
#>  magrittr      1.5        2014-11-22 CRAN (R 3.3.1)              
#>  memoise       1.0.0      2016-01-29 CRAN (R 3.3.1)              
#>  mnormt        1.5-5      2016-10-15 CRAN (R 3.3.2)              
#>  nlme          3.1-128    2016-05-10 CRAN (R 3.3.1)              
#>  plyr          1.8.4      2016-06-08 CRAN (R 3.3.1)              
#>  psych         1.6.12     2017-01-08 CRAN (R 3.3.2)              
#>  purrr         0.2.2      2016-06-18 CRAN (R 3.3.1)              
#>  quantmod      0.4-7      2016-10-24 CRAN (R 3.3.2)              
#>  R6            2.2.0      2016-10-05 CRAN (R 3.3.1)              
#>  Rcpp          0.12.9     2017-01-14 CRAN (R 3.3.2)              
#>  reshape2      1.4.2      2016-10-22 CRAN (R 3.3.2)              
#>  rlist         0.4.6.1    2016-04-04 CRAN (R 3.3.1)              
#>  rmarkdown     1.3        2016-12-21 CRAN (R 3.3.2)              
#>  rprojroot     1.2        2017-01-16 CRAN (R 3.3.1)              
#>  stringi       1.1.2      2016-10-01 CRAN (R 3.3.1)              
#>  stringr       1.1.0      2016-08-19 CRAN (R 3.3.1)              
#>  tibble        1.2        2016-08-26 CRAN (R 3.3.1)              
#>  tidyr         0.6.1      2017-01-10 CRAN (R 3.3.2)              
#>  TTR           0.23-1     2016-03-21 CRAN (R 3.3.1)              
#>  withr         1.0.2      2016-06-20 CRAN (R 3.3.1)              
#>  xts           0.9-7      2014-01-02 CRAN (R 3.3.1)              
#>  yaml          2.1.14     2016-11-12 CRAN (R 3.3.2)              
#>  zoo           1.7-14     2016-12-16 CRAN (R 3.3.2)
jbkunst commented 7 years ago

I don't have idea yet of what is going on, maybe highstocks + other plugings are producing this behavior becuase I just tried, using highchart2() which load only highcharts + 2 plugins and it works.

highchart2() %>% 
  hc_xAxis(type = 'category') %>% 
  hc_add_series_list(series_lst)

image

Yang-Tang commented 7 years ago

It's the issue of plugins/draggable-points.js. When I added it to highchart2.yaml, it became 1, 2, 3.

jbkunst commented 7 years ago

Thanks @Yang-Tang , I guess we can remove this plugin as default and put it as optional via hc_add_dependency.

Yang-Tang commented 7 years ago

That would be great! :)

Yang-Tang commented 7 years ago

Sorry to open it again. With current commit (5d76d1566b5cd8327ef206d0e63d19fff30bd434), we can now create a plot with correct axis labels, but when it is redrawn (e.g. being resized), the number labels come back again. I found it is related to a bug in highcharts.js 5.0.6 (highcharts/highcharts#6207) and is fixed in 5.0.7. When I replace the highcharts.js and highstock.js files with new ones, even with draggable-points.js loaded, the problem is fixed.

jbkunst commented 7 years ago

Ok, I'll work on that ;).

Thanks @Yang-Tang to come with this! :smiley: