I am following the following tutorial that is copy/paste reproducible here.
http://rstudio-pubs-static.s3.amazonaws.com/3369_998f8b2d788e4a0384ae565c4280aa47.html
On my setup, when I run this, I get an error
Error: Width` is deprecated. Do you want `geom_bar()`?
So I swap geom_hist
for geom_bar
, making my code...
ggplot(eventdata, aes(x = eventhour)) + geom_bar(breaks = seq(0, 24), width = 1, colour = "grey") + coord_polar(start = 0) + theme_minimal() + scale_fill_brewer() + ylab("Count") + ggtitle("Events by Time of day") + scale_x_continuous("", limits = c(0, 24), breaks = seq(0, 24), labels = seq(0, 24))
However, the graph I get is very different. Inspecting, it seems its "missing" the data from midnight to 1 AM ( 00:00:00 to 00:59:59, event_hour=0 )
I've tried running this on my own dataset (dput below) and I get a similar weird error....it combines the "0" bin and the "23" bin giving me 1 massive bin.
gplotAll = ggplot( eventdataAll, aes(x=eventdataAll$eventhour) ) +
geom_histogram(breaks=seq(0,24), colour="purple") + coord_polar(start=0) +
theme_minimal() + scale_fill_manual(values="blue") + ylab("Frequency") +
ggtitle("All Sources") + scale_x_continuous("", limits=c(0,24),
breaks=seq(0,24), labels=seq(0,24))
Note this is a very small subset of my data, as its millions of timestamps.
dput(eventdataAll[1:100,] )
structure(list(datetime = structure(c(1499433307, 1499428942,
1499426105, 1499422506, 1499466293, 1499408104, 1499476505, 1499411705,
1499400905, 1499466368, 1499454358, 1499453483, 1499405930, 1499484602,
1499483709, 1499480109, 1499408108, 1499445444, 1499439817, 1499427520,
1499418054, 1499416518, 1499414449, 1499410178, 1499409748, 1499409317,
1499405867, 1499402279, 1499485071, 1499481544, 1499481527, 1499481459,
1499481423, 1499481407, 1499477859, 1499475634, 1499474292, 1499474275,
1499474253, 1499470435, 1499468435, 1499468413, 1499468398, 1499467032,
1499464834, 1499463580, 1499463425, 1499461391, 1499460152, 1499460150,
1499459806, 1499459745, 1499459366, 1499458914, 1499458463, 1499458012,
1499457635, 1499457619, 1499455777, 1499454624, 1499454035, 1499454020,
1499452801, 1499452695, 1499450434, 1499450414, 1499450404, 1499450403,
1499450156, 1499446834, 1499446818, 1499446803, 1499445621, 1499444273,
1499443234, 1499443218, 1499443201, 1499441873, 1499441806, 1499441700,
1499441096, 1499441095, 1499440418, 1499440417, 1499436056, 1499434899,
1499432434, 1499431018, 1499428801, 1499427491, 1499425201, 1499423442,
1499421620, 1499421134, 1499427667, 1499421549, 1499472830, 1499451306,
1499450792, 1499482802), class = c("POSIXct", "POSIXt"), tzone = ""),
eventhour = c(9L, 8L, 7L, 6L, 18L, 2L, 21L, 3L, 0L, 18L,
15L, 14L, 1L, 23L, 23L, 22L, 2L, 12L, 11L, 7L, 5L, 4L, 4L,
2L, 2L, 2L, 1L, 0L, 23L, 22L, 22L, 22L, 22L, 22L, 21L, 21L,
20L, 20L, 20L, 19L, 19L, 19L, 18L, 18L, 18L, 17L, 17L, 17L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 15L, 15L,
15L, 15L, 14L, 14L, 14L, 14L, 14L, 14L, 13L, 13L, 13L, 13L,
12L, 12L, 12L, 12L, 12L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
10L, 9L, 9L, 8L, 8L, 7L, 7L, 6L, 6L, 5L, 7L, 5L, 20L, 14L,
14L, 23L)), .Names = c("datetime", "eventhour"), row.names = c(NA,
100L), class = "data.frame")
Any info on
(1) Why does the first, copy/pasted example not provide the data for "0" in the graph
and
(2) Why does my example combine the "23" and "0" bin
would be greatly appreciated.
EDIT -- The following code fixed the issue, but gave a warning. I do not think the warning is a problem, but am curious if anyone can interpret this. I believe the original issue is with R interpreting a break as (val1, val2] and not [val1, val2] like I expected. As such, the 0 groupings were never kept. Changing my breaks to seq(-1:23) is now inclusive on all values 0 through 23.
The fix :
gplotAll = ggplot( eventdataAll, aes(x=eventdataAll$eventhour) ) +
geom_histogram(breaks=seq(-1,24), colour="purple") + coord_polar(start=0) +
theme_minimal() + scale_fill_manual(values="purple") + ylab("Frequency") +
ggtitle("All Sources") + scale_x_continuous("", limits=c(-1,23),
breaks=seq(-1,23), labels=seq(0,2) )
The warning :
Removed 1 rows containing missing values (geom_bar).