I'd like to hide columns with no data in ggplot2. Here is a reproducible example using the nycflights13 library:
library(nycflights13)
library(dplyr)
library(ggplot2)
small_data <- flights %>%
mutate(date = lubridate::make_date(year, month, day)) %>%
filter(year == 2013,
month ==3)
ggplot(small_data) +
geom_bar(aes(date)) +
scale_x_date(date_labels = "%d - %b", date_breaks = "1 day") +
theme(axis.text.x = element_text(angle = 65, hjust = 1))
As yopu can see, although I have only selected data for march, I have column titles for 28 Feb and 01 April.
I have tried the following:
hide missing dates from x-axis ggplot2 (the solution no longer works)
setting (date_)breaks = levels(factor(small_data$date))
Please help me hide the unnecessary bars.