5

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?

5
  • 1
    The code works as expected for me. R3.4, ubuntu 14.04. Wonder if its to do with timezone?? Can you add the results of seesionInfo() to your question please. Commented Jun 9, 2017 at 17:06
  • Can you add the output of print(df$Dates)? Perhaps it is not Plotly related but due to some date conversion artifact. Commented Jun 10, 2017 at 12:10
  • Added sessionInfo() to my post. My print(df$dates) is exactly as I declared in my data.frame, except in Date format. Commented Jun 12, 2017 at 13:13
  • 1
    Thanks - can you add the full results from sessionInfo please so package versions can be seen. Did you try upgrading to the current R version? I tried changing various things in Sys.setlocale to match yours but still could not reproduce. Commented Jun 12, 2017 at 15:02
  • 1
    Apologies, I didn't think all this information was necessary. Perhaps it's a version issue, since I did not update to latest R due to compatibility. Commented Jun 12, 2017 at 19:49

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.