【问题标题】:Plotly dates inconsistency between axis and data frame绘制轴和数据框之间的日期不一致
【发布时间】:2017-11-11 18:28:17
【问题描述】:

我创建了一个带有 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  

如您所见,刻度从 4 月 30 日开始,当时我在数据框中的第一个值是“2017-05-01”。 hoverinfo 还显示 May 1 00h。

有人知道这是 Plotly 问题还是我的代码的问题?

【问题讨论】:

  • 代码按预期工作。 R3.4,Ubuntu 14.04。想知道它是否与时区有关?您能否将seesionInfo() 的结果添加到您的问题中。
  • 可以添加print(df$Dates)的输出吗?也许它与情节无关,但由于某些日期转换工件。
  • 在我的帖子中添加了sessionInfo()。我的 print(df$dates) 与我在 data.frame 中声明的完全一样,日期格式除外。
  • 谢谢 - 请您添加 sessionInfo 的完整结果,以便查看包版本。您是否尝试升级到当前的 R 版本?我尝试更改 Sys.setlocale 中的各种内容以匹配您的内容,但仍然无法重现。
  • 抱歉,我不认为所有这些信息都是必要的。可能是版本问题,因为兼容性问题我没有更新到最新的 R。

标签: r plotly


【解决方案1】:

这个问题很老,但我在这里检查过,新版本的 Plotly 已经纠正了这个错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-11
    • 2019-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-29
    相关资源
    最近更新 更多