我认为这是策划的问题
zoo
Date
类并在ggplot中指定日期标签。您需要将日期添加到字符串中,以便
dates
柱然后你可以用
scale_x_date
并指定
date_labels
.
library(tidyverse)
df <- data.frame(dates = c("2019-01", "2019-02", "2018-08", "2018-09", "2018-10", "2018-11", "2018-12"), values= c(0,1,2,3,4,5,6)) %>%
arrange(dates) %>%
mutate(dates = as.Date(paste0(dates, "-01")))
ggplot(df, aes(x = dates, y = values)) +
geom_bar(position="dodge", stat="identity") +
scale_x_date(date_breaks="1 month", date_labels="%Y %m") +
theme_light() +
xlab('Month') +
ylab('values')