Based on my recent OECD-package related post (http://www.supplychaindataanalytics.com/oecd-package-interface-in-r-reading-german-freight-transport-data-from-oecd-directly-in-r/) I extend my recenet analysis of German transport volume development by comparing different inland freight categories in a ggplot-chart. The data, again, i querried using the OECD-package in R.
library(OECD)
From the previous post we already know the ID-key of the transport-related dataset of interest. Using get_dataset (R function from the OECD database) I pull the data via the OECD interface in R.
data_df <- as.data.frame(get_dataset(dataset = "ITF_GOODS_TRANSPORT"))
Using dplyr I filter out the data entries of interest:
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),]
After filtering entries are still distinguished by variables indicators. In order for me to be able to interpret those I pull the data structure, using the get_data_structure function from the OECD package in R:
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)
I can now create a ggplot path plot, comparing the following categories of interest to me: – Inland road freight – Inland rail freight – Inland pipeline transport – Inland waterway transport
library(ggplot2)
ggplot(data_df[data_df$variable == c("T-GOODS-IW-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")
Data scientist focusing on simulation, optimization and modeling in R, SQL, VBA and Python
Leave a Reply