【发布时间】:2021-06-25 01:46:17
【问题描述】:
我的数据集如下所示:
> head(df,10)
# A tibble: 10 x 2
quarters `GDP Cycle`
<dttm> <dbl>
1 2000-01-01 00:00:00 -0.00973
2 2000-04-01 00:00:00 -0.000653
3 2000-07-01 00:00:00 0.0125
4 2000-10-01 00:00:00 0.0195
5 2001-01-01 00:00:00 0.00608
6 2001-04-01 00:00:00 0.00562
7 2001-07-01 00:00:00 -0.00471
8 2001-10-01 00:00:00 -0.00357
9 2002-01-01 00:00:00 -0.00137
10 2002-04-01 00:00:00 0.00144
我正在 ggplot2 上使用此代码来制作此图表:
df %>%
filter(quarters >= "2014-04-01 09:04:23" & quarters <= "2020-07-01 00:00:00") %>%
ggplot() +
aes(x = quarters, y = `GDP Cycle`) +
geom_line(size = 1L, colour = "#cb181d") +
labs(x = "Quarters", y = "% Standard deviation from trend", title = "Ecuador's Real GDP Cycle", subtitle = "Hodrick Prescott Filter | λ=1600 ", caption = "BCE GDP") +
theme_light()+ theme(plot.title = element_text(face = "bold", size = 15))+ theme(plot.subtitle = element_text(size = 10))+
geom_hline(yintercept = 0,linetype="dashed", size=1)+scale_x_yearqtr(format = '%Y.q%q',n=5)
问题是x轴,我需要像“2000.q1”这样的。
【问题讨论】: