Closed
Description
What I am trying to achieve:
Binned histograms rendered as Excel®-style grouped bar graphs, when the x axis is a timestamp.
This does exactly what I want when x is numeric:
ggplot(diamonds, aes(x = price, fill = cut)) + geom_bar(stat = "count", position = "dodge") + scale_x_binned()
The same approach doesn't work with POSIXct:
library(dplyr)
library(lubridate)
lakers %>% mutate(date = ymd(date)) %>%
ggplot(aes(x = date, fill = game_type)) + geom_bar(stat = "count", position = "dodge") + scale_x_binned()
Error: Binned scales only support continuous data
“Casting” the x into an integer is tantalizing close to what I want:
lakers %>% mutate(date = ymd(date)) %>%
ggplot(
aes(x = int(date), # Emphasis mine
fill = game_type)) +
geom_bar(stat = "count", position = "dodge") + scale_x_binned()
... but of course, the labeling on the x axis could be better.