我想隱藏ggplot2中沒有數據的列。下面是使用nycflights13庫重複的例子:在ggplot2中刪除沒有數據的日期列geom_bar
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))
正如yopu可以看出,雖然我只選擇數據遊行,我有2月28日和04月01日列標題。
我曾嘗試以下:
hide missing dates from x-axis ggplot2(溶液不再工作)
設置(date_)breaks = levels(factor(small_data$date))
請幫我隱藏了不必要的吧。
選項擴大= C(0,0)調整X比例,因此不會顯示unnecesary日期。添加「scale_x_date(date_labels =」%d - %b「,date_breaks =」1 day「,expand = c(0,0))」 – Cris