[英]controlling time-scale & binwidth on x-axis in ggplot2
Here is a dput sample of the data I am working with: 这是我正在使用的数据的dput示例:
structure(list(time = structure(c(1426552275, 1426552184, 1426552085,
1426551044, 1426550965, 1426550791, 1426550346, 1426549180, 1426549031,
1426548975), class = c("POSIXct", "POSIXt"), tzone = "EST"),
location = c("South Africa,New York City", "Utah", "United States Of Africa",
"New York", "ATLANTA", "Atlanta, GA", "New York City!", "NYC via Chicago",
"Las Vegas, Nevada, USA", "Memphis TN"), uniqueid = c(5.77553e+17,
5.77552e+17, 5.77552e+17, 5.77548e+17, 5.77547e+17, 5.77547e+17,
5.77545e+17, 5.7754e+17, 5.77539e+17, 5.77539e+17)), .Names = c("time",
"location", "uniqueid"), row.names = c(1L, 2L, 22L, 23L, 24L,
27L, 28L, 29L, 30L, 31L), class = "data.frame")
When I plot this data with time on x-axis I get: 当我在x轴上随时间绘制此数据时,我得到:
ggplot(data = temp, aes(x = time)) +
geom_bar() +
scale_x_datetime("time") +
scale_y_continuous("frequency")
When I increase the data to a 100 rows from my original dataset, I get: 当我从原始数据集中将数据增加到100行时,我得到:
Because I am not specifying binwidth, I get the message : 因为我没有指定binwidth,所以收到消息:
stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
Warning message:
position_stack requires constant width: output may be incorrect
I am not able to understand this. 我不明白这一点。 In the charts, how much time does each bar represent?
在图表中,每个条形代表多少时间? By looking at the x-axis, I can make some guess - like the first graph each bar is 1.4mins and in the second graph probably 40 mins.
通过查看x轴,我可以做出一些猜测-像第一个图形,每个条形为1.4分钟,而在第二个图形中,大概为40分钟。 But how should I calculate the value to specify in the binwidth argument?
但是我应该如何计算要在binwidth参数中指定的值?
Copying @Gregor's comment into an answer: 将@Gregor的评论复制到答案中:
Posix times (
POSIXct
) are stored in seconds, so specify a binwidth for a time duration that you want, eg,binwidth = 5 * 60
Posix时间(
POSIXct
)以秒为单位存储,因此请为所需的持续时间指定binwidth,例如binwidth = 5 * 60
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.