在 R 数据框中,我有时间变量。数据格式为 %a-%b-%d %H:%M:%S。例如,
2015-03-23 20:00:00
我只想获取以下数据
20:00:00
我已经创建了一个基于上述变量的表格并尝试制作折线图:
Var1 Var2 Freq
1 2015-03-24 00:00:00 RT 612
2 2015-03-24 01:00:00 RT 65
3 2015-03-24 06:00:00 RT 58
4 2015-03-24 07:00:00 RT 5132
5 2015-03-24 08:00:00 RT 4483
6 2015-03-24 09:00:00 RT 11112
我使用以下代码制作了 ggplot 折线图:
library(ggplot2)
library(stringr)
ggplot(rtt, aes(x = as.factor(Var1), y = Freq, colour = Var2, group = Var2)) + geom_line(size = 1) +
xlab("R Vs T") + geom_point() +
scale_x_discrete(labels = function(x) str_wrap(x, width = 2)) +
ggtitle("Number of T Vs R - through the day") +
theme(plot.title=element_text(size=rel(1.2), lineheight = 1 ))
如何从中删除 YMD 数据,因为我只想要时间而不是 x 轴中的数据,并且图表中的 x 轴看起来完全乱码。