【发布时间】:2014-04-18 03:29:24
【问题描述】:
我有很多次,想在条形图中绘制每次的频率
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 不会增加一个小时。
【问题讨论】:
-
在此处了解使用时区的一些挑战:stackoverflow.com/questions/18156015/…