Reputation: 518
I am trying to plot "breaks" counts that occur on a specific day over time. But get issues since the "Time" variable is in a date:time format and the graph fails to generate.
ggplot(df, aes(y = `Breaks`, x = `Date`)) +
geom_histogram(bins = 100, binwidth = 1, colour = "white", fill = "#1380A1")
example data:
structure(list(Date = structure(c(1544107050, 1544100120, 1540557866,
1540558168, 1544100123, 1544100135, 1545299546, 1545299518, 1545822865,
1545822864, 1545822866, 1545822875, 1546016246, 1546016252, 1546016263
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), Breaks = c(NA,
NA, 2, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1, NA)), row.names = c(NA,
15L), class = "data.frame")
Upvotes: 0
Views: 719
Reputation: 67010
library(tidyverse)
df %>%
mutate(Date = as.Date(Date)) %>%
count(Date, wt = Breaks) %>%
ggplot(aes(Date, n)) +
geom_col(colour = "white", fill = "#1380A1")
(Not sure I'm understanding the comment about "But I need the missing values in the graph that represent (o) essentially." Should zeros be represented visually somehow? BTW, the part through the count(Date = ...
line produces this -- is that what you meant by capturing the missing values?)
# A tibble: 5 x 2
Date n
<date> <dbl>
1 2018-10-26 2
2 2018-12-06 0
3 2018-12-20 0
4 2018-12-26 0
5 2018-12-28 1
Upvotes: 2