首页 文章

Plotly表示轴和数据框之间的不一致

提问于
浏览
5

我在x轴上创建了一个带有日期的绘图条形图,但是刻度与实际日期不匹配 .

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

正如您所看到的,刻度从4月30日开始,当时我在数据框中的第一个值是“2017-05-01” . hoverinfo也显示5月1日00h .

有谁知道这是一个Plotly问题还是我的代码?

1 回答

  • 1

    这个问题很老但我在这里查了一下,Plotly的新版本已经纠正了这个失败 .

相关问题