R-避免使用lubridate hms和ggplot显示毫秒
我有不同的数据帧(df),每个数据帧的持续时间向量如下:R-避免使用lubridate hms和ggplot显示毫秒,r,ggplot2,lubridate,R,Ggplot2,Lubridate,我有不同的数据帧(df),每个数据帧的持续时间向量如下: Duration 02:05:30 01:00:58 00:40:21 00:54:26 我试图用ggplot以以下方式绘制这些持续时间: df$Duration <- lubridate::hms(df$Duration) p <- ggplot(df, aes(Duration)) + scale_x_time("Duration") + stat_bin(aes(y =.
Duration
02:05:30
01:00:58
00:40:21
00:54:26
我试图用ggplot以以下方式绘制这些持续时间:
df$Duration <- lubridate::hms(df$Duration)
p <- ggplot(df, aes(Duration)) + scale_x_time("Duration") +
stat_bin(aes(y =..count..), bins=30, fill = 'darkblue') +
scale_y_continuous(sec.axis = sec_axis(~./nrow(df), labels=percent))
df$Duration如果您希望X轴标签类似于2H 5M 30S
,那么您可以尝试这种方法
库(ggplot2)
图书馆(lubridate)
df$Duration谢谢,但我不想在POSIXct中转换数据,因为我必须处理超过24小时的持续时间,而POSIXct不支持这种情况。是否有可能在缩放时间内设置标签格式?如果有帮助,请不要忘记。
df <- structure(list(Duration = c("02:05:30", "01:00:58", "00:40:21",
"00:54:26")), .Names = "Duration", class = "data.frame", row.names = c(NA,
-4L))