wangleihong的个人博客分享 http://blog.sciencenet.cn/u/wangleihong

博文

数据整理和拼图小例

已有 1581 次阅读 2022-12-3 23:55 |系统分类:教学心得

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://m.sciencenet.cn/blog-3509182-1366418.html

上一篇:ggplot2的函数式编程

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-28 04:27

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部