王雷宏
数据整理和拼图小例
2022-12-3 23:55
阅读:1891

library("lubridate")
library("tidyverse")
ec2 <- economics %>%
  as_tibble() %>%
  transmute(year=year(date),month=month(date),rate=uempmed) %>%
  filter(year>2005) %>%
  spread(year,rate)
ec2 <- gather(ec2,key=year,value = unemp, '2006':'2015',convert = TRUE,na.rm = TRUE)

p1 <- ggplot(ec2,aes(year+(month-1)/12,unemp))+
  geom_line()
p2 <- ggplot(ec2,aes(month,unemp,group=year))+
  geom_line(aes(colour=year),size=1)
library(ggpubr)
ggarrange(p1, p2,labels = c("A", "B"),
          ncol = 2, nrow = 1)
ggsave("11.tiff",width = 16,height = 10,units=c("cm"),dpi=300)11.jpg

转载本文请联系原作者获取授权,同时请注明本文来自王雷宏科学网博客。

链接地址:https://wap.sciencenet.cn/blog-3509182-1366418.html?mobile=1

收藏

分享到:

下一篇
当前推荐数:0
推荐到博客首页
网友评论0 条评论
确定删除指定的回复吗?
确定删除本博文吗?