R 绘图仪中的时间序列
所以,我有这些数据R 绘图仪中的时间序列,r,ggplot2,plotly,R,Ggplot2,Plotly,所以,我有这些数据 test_data <- structure(list( time = c(29510, 29528.023023023, 29546.046046046, 29564.0690690691, 29582.0920920921, 29600.1151151151, 29618.1381381381, 29636.1611611612, 29654.1841841842, 29672.207207
test_data <- structure(list(
time = c(29510, 29528.023023023, 29546.046046046,
29564.0690690691, 29582.0920920921, 29600.1151151151,
29618.1381381381, 29636.1611611612, 29654.1841841842,
29672.2072072072, 29690.2302302302, 29708.2532532533,
29726.2762762763, 29744.2992992993, 29762.3223223223,
29780.3453453453, 29798.3683683684, 29816.3913913914,
29834.4144144144, 29852.4374374374),
sum = c(0L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 5L, 7L, 9L, 9L, 15L,
17L, 18L, 18L, 18L, 18L, 21L)),
.Names = c("time", "sum"),
row.names = c(NA, 20L),
class = "data.frame")
但是当我尝试使用plot\ly
时,时间作为数字而不是时间错误地显示出来。plotly中是否有类似于ggplot2的scale\u x\u time
功能
plot_ly(test_data, x = ~time, y = ~sum, type = 'scatter', mode = 'lines')
那么,整合@Z.Lin的建议,消除一天中的必要性:
test_data$time <- as.POSIXct(test_data$time, origin = "1970-01-01") # as date
test_data$time <- strftime(test_data$time,format="%H:%M:%S") # remove the day
plot_ly(test_data, x = ~time, y = ~sum, type = 'scatter', mode = 'lines')
test_data$time这几乎可以工作,尽管我不喜欢使用ggplot设置。但是重叠行时出现的文本仍然显示数字而不是时间如果将time
变量转换为date-time类,则plot\ly
代码将正常工作。例如:测试数据$time
test_data$time <- as.POSIXct(test_data$time, origin = "1970-01-01") # as date
test_data$time <- strftime(test_data$time,format="%H:%M:%S") # remove the day
plot_ly(test_data, x = ~time, y = ~sum, type = 'scatter', mode = 'lines')