When i use a barplot to plot hourly data, the bars are divided by the x-axis tickmark at X o´clock sharp. The data corresponds to 6-7 o´clock, 7-8 o´clock and so on. I want each bar to start at x o´clock sharp and not at x - 0:30 min.
Code example:
install.packages("nycflights13")
library(nycflights13)
data <- flights %>% select(time_hour, hour) %>%
mutate(flightdate = floor_date(time_hour, "day")) %>%
filter(flightdate == as_date("2013-01-01")) %>% group_by(flightdate,hour) %>% tally() %>%
mutate(flightdatetime = as_datetime(paste(flightdate + hours(hour)))) %>%
select(flightdatetime,n)
ggplot() +
geom_col(aes(x=flightdatetime, y = n),
data = data, color = "black", fill = "black") +
ggplot2::scale_x_datetime(labels = date_format("%H:%M", tz = "Europe/Berlin"), date_breaks = "1 hour") +
theme_minimal() + labs(title ="Flights per hour")