基于我最近的OECD软件包相关文章(http://www.supplychaindataanalytics.com/oecd-package-interface-in-r-reading-german-freight-transport-data-from-oecd-direct-in-r/)通过在ggplot图表中比较不同的内陆货运类别,我扩展了对德国运输量发展的分析。再次使用OECD R包查询数据。
library(OECD)
从上一篇文章中,我们已经知道了与运输相关的数据集的ID密钥。使用get_dataset(来自OECD数据库的R函数),我通过R中的OECD接口提取数据。
data_df <- as.data.frame(get_dataset(dataset = "ITF_GOODS_TRANSPORT"))
使用dplyr筛选出感兴趣的数据条目:
library(dplyr)
colnames(data_df) <- c("country","variable","timeformat","unit","powercode","obsTime","obsValue","obsStatus")
data_df <- dplyr::filter(data_df,country=="DEU")
data_df <- dplyr::filter(data_df,timeformat=="P1Y")
data_df <- dplyr::filter(data_df,unit=="TONNEKM")
data_df <- data_df[is.na(data_df$obsStatus),]
过滤后,条目仍由变量指示符区分。为了使我能够解释这些数据,我使用R中OECD包中的get_data_structure函数来提取数据结构:
data_struct <- get_data_structure("ITF_GOODS_TRANSPORT")
data_struct$VARIABLE
## id label
## 1 T-GOODS-TOT-INLD Total inland freight transport
## 2 T-GOODS-RL-TOT Rail freight transport
## 3 T-GOODS-RD-TOT Road freight transport
## 4 T-GOODS-RD-REW Road freight transport for hire and reward
## 5 T-GOODS-RD-OWN Road freight transport on own account
## 6 T-GOODS-IW-TOT Inland waterways freight transport
## 7 T-GOODS-PP-TOT Pipelines transport
## 8 T-SEA-CAB Coastal shipping (national transport)
## 9 T-SEA Maritime transport
## 10 T-CONT-RL-TEU Rail containers transport (TEU)
## 11 T-CONT Containers transport
## 12 T-CONT-RL-TON Rail containers transport (weight)
## 13 T-CONT-SEA-TEU Maritime containers transport (TEU)
## 14 T-CONT-SEA-TON Maritime containers transport (weight)
我现在可以创建一个ggplot路径图,比较以下感兴趣的类别:1)内陆货运2)内陆铁路货运3)内陆管道运输4)内陆水路运输
library(ggplot2)
ggplot(data_df[data_df$variable == c("T-GOODS-IW-TOT",
"T-GOODS-PP-TOT",
"T-GOODS-RD-TOT",
"T-GOODS-RL-TOT"),]) +
geom_path(mapping = aes(x=as.numeric(obsTime),y=obsValue, color=variable)) +
ggtitle("German inland freight development by considered category") +
xlab("year") +
ylab("in millions of TONNEKM")
用于访问公共经济数据的另一个有趣的软件包是fredr软件包,它提供对FRED数据库的访问。
专业领域为优化和仿真的工业工程师(R,Python,SQL,VBA)
Leave a Reply