Created
May 18, 2026 23:24
-
-
Save abikoushi/e44796491c6cac4b3c74dc91d78c8e81 to your computer and use it in GitHub Desktop.
Plot GDP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(readr) | |
| library(dplyr) | |
| library(ggplot2) | |
| library(tidyr) | |
| ### | |
| #data | |
| #https://www.esri.cao.go.jp/jp/sna/data/data_list/sokuhou/files/2025/qe254_2/gdemenuja.html | |
| ### | |
| path <- "./data/GDP/gaku-jk2542.csv" | |
| dat <- read_csv(path, skip = 5, n_max=128) | |
| dat <- dat[-1,] | |
| dat <- rename(dat, time = ...1) | |
| dat <- mutate(dat, NetExports = as.numeric(sub(",","",`Goods & Services`,))) %>% | |
| mutate(C=PrivateConsumption, | |
| I=PrivateResidentialInvestment+ | |
| `Private Non-Resi.Investment`+ | |
| `Changein PrivateInventories`+ | |
| `Changein PublicInventories`+ | |
| PublicInvestment, | |
| G=GovernmentConsumption, | |
| NX=NetExports) %>% | |
| mutate(i=row_number()) | |
| # plot(dat$C+dat$I+dat$G+dat$NX+dat$Residual, | |
| # dat$`GDP(Expenditure Approach)` ) | |
| # abline(0,1) | |
| dat_long <- dplyr::select(dat,time,i,C,I,G,NX,Residual) %>% | |
| pivot_longer(C:Residual) | |
| p <- ggplot(dat_long, aes(x=factor(i),y=value,fill=name, group = name))+ | |
| geom_area()+ | |
| scale_x_discrete(labels = dat$time)+ | |
| scale_fill_viridis_d()+ | |
| labs(x="time", y="GDP",title="実質季節調整系列")+ | |
| theme_classic(base_family = "Osaka")+ | |
| theme(axis.text.x = element_text(angle=90, hjust=1)) | |
| print(p) | |
| ggsave(plot = p, filename = "GDP.png", width = 15, height = 6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment