如何在R的X轴上绘制时间(HH:MM:SS) [英] How do I plot time (HH:MM:SS) in X axis in R
问题描述
我试图通读stackoverflow,博客,书籍等,但无法找到以以下格式(HH:MM:SS.000)以R表示的在x轴上绘制时间的答案,而没有找到关于R的其他数量的答案.y轴.我有以下数据集:
I have tried to read through stackoverflow, blogs, books etc but have been unable to find the answer on plotting time in the x-axis in the following format(HH:MM:SS.000) in R and another quantity on the y-axis. I have the following dataset:
Time EcNo
12:54:09.000 -14.47
12:54:10.000 -17.96
12:54:11.000 -15.97
12:54:12.000 -14.61
12:54:13.000 -12.68
12:54:14.000 -10.73
12:54:15.000 -10.54
12:54:16.000 -11.62
12:54:17.000 -12.49
12:54:18.000 -11.12
如何将Hc:MM:SS.000格式的EcNo绘制在Y轴与时间(x轴)上,如上所示.
How would I plot EcNo on Yaxis vs Time(x axis) in the format HH:MM:SS.000 as shown above.
老实说,我将感谢您的帮助.非常感谢
I honestly would appreciate some help. many thanks
推荐答案
您也可以尝试 ggplot
:
library(ggplot2)
df$time <- as.POSIXct(strptime(df$Time, format="%H:%M:%S"))
# Automatic scale selection
ggplot(data = df, aes(x = time, y = EcNo)) + geom_point()
scale_x_datetime
是 ggplot
函数,但是对于精美的参数 date_breaks
和 date_format
,您需要打包<代码>比例:
scale_x_datetime
is a ggplot
function, but for the nice arguments date_breaks
, and date_format
you need package scales
:
library(scales)
ggplot(data = df, aes(x = time, y = EcNo)) + geom_point() +
scale_x_datetime(breaks = date_breaks("1 sec"), labels = date_format("%S"))
ggplot(data = df, aes(x = time, y = EcNo)) + geom_point() +
scale_x_datetime(breaks = date_breaks("1 sec"), labels = date_format("%OS3"))
ggplot(data = df, aes(x = time, y = EcNo)) + geom_point() +
scale_x_datetime(breaks = date_breaks("4 sec"), labels = date_format("%M:%S"))
这篇关于如何在R的X轴上绘制时间(HH:MM:SS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!