This work is part of an assignment of Commerce and Circulation chair at UNIMONTES and is currently under development. Feel free to ask me any questions.
library(tidyverse)
library(sf)
library(tmap)
library(wbstats)
library(geobr)
railways_goods <- wb_data("IS.RRS.GOOD.MT.K6", mrnev = 1)
railways_goods <- railways_goods %>%
arrange(-IS.RRS.GOOD.MT.K6) %>%
rename(GOODS_T = IS.RRS.GOOD.MT.K6)
railways_people <- wb_data("IS.RRS.PASG.KM", mrnev = 1)
railways_people <- railways_people %>%
arrange(-IS.RRS.PASG.KM) %>%
rename(PEOPLE_T = IS.RRS.PASG.KM)
population <- wb_data("SP.POP.TOTL", mrnev = 1)
population <- population %>%
rename(POPULATION = SP.POP.TOTL)
gdp_ppp <- wb_data("NY.GDP.PCAP.PP.CD", mrnev = 1)
gdp_ppp <- gdp_ppp %>%
rename(GDP_PPP = NY.GDP.PCAP.PP.CD)
dataset <- railways_goods %>%
select(iso3c, GOODS_T) %>%
full_join(
railways_people %>%
select(iso3c, PEOPLE_T),
by = "iso3c"
) %>%
full_join(
population %>%
select(iso3c, POPULATION),
by = "iso3c"
) %>%
full_join(
gdp_ppp %>%
select(iso3c, GDP_PPP),
by = "iso3c"
)
Although there are some exceptions, it is noticeable that there is some positive correlaetion between the goods transported and the people transported within countries.
dataset %>%
ggplot() +
geom_point(aes(GOODS_T, PEOPLE_T)) +
geom_smooth(aes(GOODS_T, PEOPLE_T), method = "lm", se = FALSE) +
annotate("text", label = paste0("Pearson: ", format(cor(dataset$GOODS_T, dataset$PEOPLE_T, use = "complete"), digits = 2)), x = 10, y = 10000) +
scale_x_log10() +
scale_y_log10()
dataset %>%
ggplot() +
geom_point(aes(GDP_PPP, GOODS_T)) +
geom_smooth(aes(GDP_PPP, GOODS_T), method = "lm", se = FALSE) +
annotate("text", label = paste0("Pearson: ", format(cor(dataset$GDP_PPP, dataset$GOODS_T, use = "complete"), digits = 2)), x = 2e3, y = 1e5) +
scale_x_log10() +
scale_y_log10()
dataset %>%
ggplot() +
geom_point(aes(POPULATION, PEOPLE_T)) +
geom_smooth(aes(POPULATION, PEOPLE_T), method = "lm", se = FALSE) +
annotate("text", label = paste0("Pearson: ", format(cor(dataset$POPULATION, dataset$PEOPLE_T, use = "complete"), digits = 2)), x = 1e5, y = 1e4) +
scale_x_log10() +
scale_y_log10()
dataset %>%
filter(!is.na(GOODS_T)) %>%
mutate(
iso3c = as_factor(iso3c) %>%
fct_reorder(-GOODS_T) %>%
fct_lump(5, w = GOODS_T)
) %>%
ggplot() +
geom_col(aes(x = iso3c, y = GOODS_T))
dataset %>%
filter(!is.na(PEOPLE_T)) %>%
mutate(
iso3c = as_factor(iso3c) %>%
fct_reorder(-PEOPLE_T) %>%
fct_lump(5, w = PEOPLE_T)
) %>%
ggplot() +
geom_col(aes(x = iso3c, y = PEOPLE_T))
Top 5 countries and Brazil
dataset %>%
filter(!is.na(GOODS_T)) %>%
mutate(
iso3c = ifelse(
iso3c == "BRA",
"BRA",
iso3c %>%
as_factor() %>%
fct_reorder(-GOODS_T) %>%
fct_lump(5, w = GOODS_T) %>% as.character()
) %>%
as_factor() %>%
fct_reorder(-GOODS_T)
) %>%
ggplot() +
geom_col(aes(x = iso3c, y = GOODS_T))
Top 5 countries and Brazil
dataset %>%
filter(!is.na(PEOPLE_T)) %>%
mutate(
iso3c = ifelse(
iso3c == "BRA",
"BRA",
iso3c %>%
as_factor() %>%
fct_reorder(-PEOPLE_T) %>%
fct_lump(5, w = PEOPLE_T) %>% as.character()
) %>%
as_factor() %>%
fct_reorder(-PEOPLE_T)
) %>%
ggplot() +
geom_col(aes(x = iso3c, y = PEOPLE_T))
states <- read_state(showProgress = FALSE)
## Using year 2010
## Loading data for the whole country
head(states)
## Simple feature collection with 6 features and 5 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -73.99045 ymin: -13.6937 xmax: -46.06095 ymax: 5.271841
## geographic CRS: SIRGAS 2000
## code_state abbrev_state name_state code_region name_region
## 1 11 RO Rondônia 1 Norte
## 2 12 AC Acre 1 Norte
## 3 13 AM Amazonas 1 Norte
## 4 14 RR Roraima 1 Norte
## 5 15 PA Pará 1 Norte
## 6 16 AP Amapá 1 Norte
## geom
## 1 MULTIPOLYGON (((-63.32721 -...
## 2 MULTIPOLYGON (((-73.18253 -...
## 3 MULTIPOLYGON (((-67.32609 2...
## 4 MULTIPOLYGON (((-60.20051 5...
## 5 MULTIPOLYGON (((-54.95431 2...
## 6 MULTIPOLYGON (((-51.1797 4....
bra_railways <- st_read("../data/ferrovias_2014.shp", quiet = TRUE)
head(bra_railways)
## Simple feature collection with 6 features and 5 fields
## geometry type: LINESTRING
## dimension: XY
## bbox: xmin: -52.00262 ymin: 0.6371377 xmax: -51.62217 ymax: 0.8951862
## geographic CRS: SIRGAS 2000
## OBJECTID FERROVIA OPERADORA CODPNVSIMP COD_PNV
## 1 1 Serra do Navio - Porto Santana MMX LogÃstica EF-401 401FAP0030
## 2 2 Serra do Navio - Porto Santana MMX LogÃstica EF-401 401FAP0020
## 3 3 Serra do Navio - Porto Santana MMX LogÃstica EF-401 401FAP0010
## 4 4 Serra do Navio - Porto Santana MMX LogÃstica EF-401 401FAP0040
## 5 5 Serra do Navio - Porto Santana MMX LogÃstica EF-401 401FAP0050
## 6 6 Serra do Navio - Porto Santana MMX LogÃstica EF-401 401FAP0060
## geometry
## 1 LINESTRING (-51.88659 0.705...
## 2 LINESTRING (-51.92701 0.754...
## 3 LINESTRING (-51.94401 0.777...
## 4 LINESTRING (-51.85297 0.681...
## 5 LINESTRING (-51.74405 0.637...
## 6 LINESTRING (-51.62217 0.653...
tm_shape(states) +
tm_borders(col = "lightgrey") +
tm_shape(bra_railways) +
tm_lines(lwd = 2, lty = 1, col = "FERROVIA") +
tm_compass(position = c("right", "top")) +
tm_scale_bar(position = c("right", "bottom")) +
tm_layout(
main.title = "Brazilian railways",
legend.outside = TRUE,
legend.outside.size = .45
)