Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R-避免使用lubridate hms和ggplot显示毫秒_R_Ggplot2_Lubridate - Fatal编程技术网

R-避免使用lubridate hms和ggplot显示毫秒

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 =.

我有不同的数据帧(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 =..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))