我有很多次,想在条形图中绘制每次的频率
library(ggplot2)
library(chron)
test <- data.frame(times = c(rep("7:00:00",4), rep("8:00:00",3),
rep("12:00:00",1), rep("13:00:00",5)))
test$times <- times(test$times)
test
times
1 07:00:00
2 07:00:00
3 07:00:00
4 07:00:00
5 08:00:00
6 08:00:00
7 08:00:00
8 12:00:00
9 13:00:00
10 13:00:00
11 13:00:00
12 13:00:00
13 13:00:00
选择的值binwidth
代表分钟
p <- ggplot(test, aes(x = times)) + geom_bar(binwidth=1/24/60)
p + scale_x_chron(format="%H:%M")
如您所见,刻度在 x 轴上加一小时:
我觉得这与时区有关,但我不能真正放置它:
Sys.timezone()
[1] "CET"
编辑:感谢@shadow 发表评论
更新:
如果我Sys.setenv(TZ='GMT')
先运行,它会完美运行。问题出在times()
功能上。我自动将时区设置为GMT
,如果我正在绘制 x 轴,ggplot 会注意到我的系统时区是CET
,并在图上增加一小时。现在,如果我将系统时区设置为GMT
, ggplot 不会增加一个小时。