Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotly dates inconsistency between axis and data frame

Tags:

r

plotly

I created a plotly bar chart with dates on the x-axis, but the ticks are not matching the actual dates.

df <- data.frame(
  Dates = c("2017-05-01", "2017-05-02", "2017-05-03", "2017-05-04")
  ,Values = c(22, 44, 66, 88)
  ,stringsAsFactors = FALSE
)

df$Dates <- as.Date(df$Dates)

plot_ly(
  data = df, x = ~Dates, y = ~Values
  ,type = "bar"
)

sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.12.2 (Sierra)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] plotly_4.5.2  ggplot2_2.2.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.3       tidyr_0.6.0       viridisLite_0.1.3
 [4] digest_0.6.9      dplyr_0.5.0       assertthat_0.2.0 
 [7] grid_3.3.1        plyr_1.8.3        R6_2.2.1         
[10] jsonlite_1.4      gtable_0.1.2      DBI_0.5-1        
[13] magrittr_1.5      scales_0.4.1      neuralnet_1.33   
[16] httr_1.2.1        lazyeval_0.2.0    tools_3.3.1      
[19] htmlwidgets_0.8   purrr_0.2.2       munsell_0.4.3    
[22] base64enc_0.1-3   colorspace_1.2-6  htmltools_0.3.5  
[25] tibble_1.2  

enter image description here

As you can see, the ticks begin at Apr 30, when my first value in the data frame is "2017-05-01". The hoverinfo also shows May 1 00h.

Does anyone know if this is a Plotly issue or something with my code?

like image 670
mnaga Avatar asked Nov 08 '22 21:11

mnaga


1 Answers

This question is old but I checked it here and the new versions of Plotly have corrected this failure.

like image 199
Matheus Tramontini Avatar answered Nov 15 '22 07:11

Matheus Tramontini