datastorm-open / rAmCharts

API for Amcharts
48 stars 16 forks source link

amTimeSeries, different hours are grouped at the same hour on the x-axis ? #78

Closed cedricbriandgithub closed 6 years ago

cedricbriandgithub commented 6 years ago

Hi

I've started using your package which I find quite excellent. I have a question regarding the formatting of the following dataset (reproducible code):


library("rAmCharts")
library("pipeR")
d10am <- structure(list(horodate = structure(c(1436940000, 1436950800, 
                1436961600, 1436968800, 1436983200, 1436986800, 1437026400, 1437030000, 
                1437037200, 1437048000, 1437055200, 1437069600, 1437073200, 1437112800, 
                1437116400, 1437123600, 1437134400, 1437141600, 1437148800, 1437156000, 
                1437159600, 1437206400, 1437210000, 1437220800, 1437228000, 1437235200, 
                1437242400, 1437246000, 1437195600, 1437199200, 1437202800), class = c("POSIXct", 
                "POSIXt"), tzone = ""), Avant_inf_seuil = c(1, 2, NA, NA, NA, 
            2, 2, 1, 6, 4, NA, NA, 3, 3, 2, 5, NA, NA, NA, NA, 3, 2, 1, 6, 
            4, NA, NA, NA, 1, 2, 2), Avant_sup_seuil = c(NA, NA, 10, 19, 
            22, NA, NA, NA, NA, NA, 24, 18, NA, NA, NA, NA, 15, 25, 20, 10, 
            NA, NA, NA, NA, NA, 18, 13, 8, NA, NA, NA), Apres_inf_seuil = c(1, 
            2, NA, NA, NA, 0, 0, 0, 0, 4, NA, NA, 0, 0, 0, 0, NA, NA, NA, 
            NA, 0, 0, 0, 0, 0, NA, NA, NA, 0, 0, 0), Apres_sup_seuil = c(NA, 
            NA, 10, 19, 24, NA, NA, 9, NA, NA, 24, 21, NA, NA, 10, NA, 15, 
            25, 20, 13, NA, NA, 5, NA, 10, 18, 13, 8, NA, 3, NA)), .Names = c("horodate", 
        "Avant_inf_seuil", "Avant_sup_seuil", "Apres_inf_seuil", "Apres_sup_seuil"
    ), row.names = c("37216", "37220", "37221", "37224", "37226", 
        "37227", "37228", "37231", "37232", "37235", "37237", "37239", 
        "37240", "37242", "37244", "37245", "37247", "37250", "37252", 
        "37254", "37256", "37257", "37259", "37261", "37262", "37264", 
        "37266", "37268", "37269", "37271", "37273"), class = "data.frame")
col <- c("greenyellow","#1D4669","yellow","#39CCCC")
amTimeSeries(d10am, 'horodate', 
        c("Avant_inf_seuil","Avant_sup_seuil","Apres_inf_seuil","Apres_sup_seuil"), 
        bullet = c("round","square","round","square"),
        color=col,
        backgroundColor="#40555E",
        backgroundAlpha=0.4,
        bulletSize = c(12,12,8,8),
        aggregation="Sum",
        fillAlphas =c(0,0,0.5,0.5),
        groupToPeriods = c('30mm','hh', 'DD', 'MM','MAX'), 
        linewidth = c(0, 0, 0, 0),
        legend = TRUE,
        maxSeries = 200)%>>%
    setExport(enabled = TRUE)  

Which is just an extraction from a larger dataset. In the dataset, the first values for day 2015-07-16 are at 08:00 and 09:00, however they are displayed on the same horodate (8:00) on the chart.

                 horodate Avant_inf_seuil Avant_sup_seuil Apres_inf_seuil
37228 2015-07-16 08:00:00               2              NA               0
37231 2015-07-16 09:00:00               1              NA               0
      Apres_sup_seuil
37228              NA
37231               9

This problem is not reproduced for every dataset extraction.

image

I've noticed that in amcharts documentation they say that

Side note: in all cases, except when working with daily data, you should remember setting minPeriod of CategoryAxesSettings to the period you use. For example, if your data is hourly, you should set:

categoryAxesSettings.minPeriod = "hh";

However I was unable to pass the argument categoryAxesSettings.minPeriod = "30mm" to the function. In addition when running the plot I get the following message

Warning message: In controlgroupToPeriods(groupToPeriods, difft) : NAs introduced by coercion

Am I missing something ? Any help will be much welcome.

Merci d'avance

Cédric

> sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 16299)

Matrix products: default

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

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

other attached packages:
 [1] pipeR_0.6.1.3   rAmCharts_2.1.5 rj_2.1.0-13     stringr_1.2.0  
 [5] reshape2_1.4.3  Hmisc_4.1-0     ggplot2_2.2.1   Formula_1.2-2  
 [9] survival_2.41-3 lattice_0.20-35

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.14        compiler_3.4.3      RColorBrewer_1.1-2 
 [4] plyr_1.8.4          bindr_0.1           base64enc_0.1-3    
 [7] tools_3.4.3         rpart_4.1-11        digest_0.6.13      
[10] jsonlite_1.5        tibble_1.3.4        gtable_0.2.0       
[13] checkmate_1.8.5     htmlTable_1.11.0    pkgconfig_2.0.1    
[16] rlang_0.1.6         Matrix_1.2-12       rstudioapi_0.7     
[19] yaml_2.1.16         bindrcpp_0.2        gridExtra_2.3      
[22] dplyr_0.7.4         cluster_2.0.6       knitr_1.17         
[25] htmlwidgets_0.9     grid_3.4.3          nnet_7.3-12        
[28] data.table_1.10.4-3 glue_1.2.0          R6_2.2.2           
[31] foreign_0.8-69      latticeExtra_0.6-28 purrr_0.2.4        
[34] tidyr_0.7.2         magrittr_1.5        backports_1.1.2    
[37] scales_0.5.0        htmltools_0.3.6     splines_3.4.3      
[40] assertthat_0.2.0    colorspace_1.3-2    stringi_1.1.6      
[43] acepack_1.4.1       lazyeval_0.2.1      munsell_0.4.3      
[46] zoo_1.8-0  
bthieurmel commented 6 years ago

Hi,

amTimeSeries doesn't like incomplete time series... In your case, we begin with 3hours data, but sometimes we have some hours data. I think you have first to complete with missing values to lower time step.

amTimeSeries try to find the time step with first point for send value to javascript, so 3 hours in your case, and so after, you have some bugs near to hour data.

Moreover, it's a bad idea to set groupToPeriods lower than data time step.

Cheers

cedricbriandgithub commented 6 years ago

Many thanks for that reply !!