【发布时间】:2022-11-13 21:49:01
【问题描述】:
我正在尝试使用 fredr 包和管道 (%>%) command in ggplot2. I am struggling to use the xlim()orlims()` 命令使用 St Louis Fed 数据绘制图。
我可以使用以下代码轻松生成我想要的图(但没有正确的图限制)。
#libraries
library(tidyverse)
library(fredr)
library(ggthemes)
#make the plot
map_dfr(c("LABSHPUSA156NRUG", "W273RE1A156NBEA"), fredr) %>%
pivot_wider(
names_from = series_id,
values_from = value) %>%
mutate(., labour_share_of_profit = LABSHPUSA156NRUG/W273RE1A156NBEA) %>%
ggplot(data = ., mapping = aes(x = date, y =labour_share_of_profit)) +
geom_line(lwd=1.2) +
labs(x = "Year", y = "Share of Labour Compensation as Proportion of Profit") +
theme(legend.position = "none") +
theme_wsj()
%>%
{ggsave(filename = "p1_wsj.pdf",
device = "pdf",
width = 10*sqrt(2), height = 10)
}
这将产生以下图。
现在,如何使用 xlim() 函数来设置系列开头的情节限制?
【问题讨论】:
-
下次请用
df <- dput()做一个可重现的例子。