默认情况下,plotly会根据数据的范围创建x轴。最小值和最大值之间的步长是等距的。连续的时间轴——在我看来没有什么“奇怪”的(数字数据也是如此)。
但是,如果您更想按类别查看数据,可以使用
factor()
:
library(plotly)
datetime<-c("2011-06-04 12:00:00","2011-06-04 14:00:00","2011-06-04 15:00:00","2011-07-04 18:00:00")
name<-c(5,10,15,20)
SAMPLE<-data.frame(datetime,name)
SAMPLE$datetime<-as.POSIXct(SAMPLE$datetime,format="%Y-%m-%d %H:%M:%S")
fig <- plot_ly(SAMPLE, x = ~factor(datetime), y = ~name, type = 'bar',
marker = list(color = 'rgb(158,202,225)',
line = list(color = 'rgb(8,48,107)',
width = 1.5)))
fig