2017-02-23 63 views
0

我的馬拉松整理次向量我想在R.顯示Plotly直方圖時間爲hh:mm:ss的

使用 plot_ly函數來繪製與x軸的直方圖以小時和分鐘 hh:mm:ss格式/箱
library(plotly) 

R<-c("02:17:20", "02:17:26", "02:19:17", "02:19:18", "02:20:50", "02:21:20") 

plot_ly(x = as.difftime(R), type = "histogram") 

的x軸和在圖表顯示以十進制格式即2.325代替2:19:30我假定這個彈出是因爲我使用的difftime類。是否可以更改圖形的格式以hh:mm:ss格式顯示它?

Plot_ly running times histogram

回答

0

你可以做同樣的伎倆像here,即轉換您的時間爲日期時間。假設他們有時在1970/01/01完成,但我們只會報告時間(tickformat="%H:%M:%S")。

請注意,這會看起來有點不同於您的原始示例,因爲劇情隨意決定以不同的方式放置垃圾箱。

library(plotly) 
library('magrittr') 

R<-c("02:17:20", "02:17:26", "02:17:46", "02:18:26", "02:18:46", "02:19:17", "02:19:18", "02:20:50", "02:21:20") 

R <- paste('1970-01-01', R) 
R <- strptime(R, format="%Y-%m-%d %H:%M:%S") 

plot_ly(x = (as.numeric(R) * 1000), type = "histogram") %>% 
    layout(xaxis=list(type="date", tickformat="%H:%M:%S")) 

enter image description here

+0

這一工程十分感謝。只是爲了我在'plot_ly'調用中的理解,您將數字日期時間乘以1000,因爲在plotly/js中,日期時間從1970/01/01開始計爲毫秒,R秒爲止? –