major_ports<-read_csv("major_ports.csv")
## Rows: 177 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): Postal, Type, ISO3, REGION
## dbl (3): OBJECTID, Lat, Lng
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
names(major_ports)
## [1] "OBJECTID" "Postal" "Lat" "Lng" "Type" "ISO3" "REGION"
major_ports <- major_ports %>%
rename(Country = ISO3)
region_ports <- major_ports %>%
group_by(REGION) %>%
summarize(number_of_ports = n()) %>%
arrange(desc(number_of_ports))
print(paste("The top 5 regions by number of major ports are:"))
## [1] "The top 5 regions by number of major ports are:"
head(region_ports, 5)
## # A tibble: 5 × 2
## REGION number_of_ports
## <chr> <int>
## 1 Latin America & Caribbean 49
## 2 Sub-Saharan Africa 42
## 3 East Asia & Pacific 28
## 4 South Asia 22
## 5 Middle East & North Africa 13
port_type <- major_ports %>%
count(Type)
print(paste("The number of major ports by type is:"))
## [1] "The number of major ports by type is:"
port_type
## # A tibble: 2 × 2
## Type n
## <chr> <int>
## 1 Bulk 65
## 2 General 112
port_typeR <- major_ports %>%
group_by(REGION, Type) %>%
summarize(number_of_ports = n()) %>%
arrange(desc(number_of_ports))
## `summarise()` has regrouped the output.
## ℹ Summaries were computed grouped by REGION and Type.
## ℹ Output is grouped by REGION.
## ℹ Use `summarise(.groups = "drop_last")` to silence this message.
## ℹ Use `summarise(.by = c(REGION, Type))` for per-operation grouping
## (`?dplyr::dplyr_by`) instead.
top5_port_typeR <- port_typeR %>%
subset(REGION %in% head(region_ports$REGION, 5))
print(paste("The number of General and Bulk ports across the top 5 regions is:"))
## [1] "The number of General and Bulk ports across the top 5 regions is:"
top5_port_typeR
## # A tibble: 10 × 3
## # Groups: REGION [5]
## REGION Type number_of_ports
## <chr> <chr> <int>
## 1 Latin America & Caribbean General 34
## 2 Sub-Saharan Africa General 29
## 3 East Asia & Pacific General 15
## 4 Latin America & Caribbean Bulk 15
## 5 East Asia & Pacific Bulk 13
## 6 Sub-Saharan Africa Bulk 13
## 7 South Asia Bulk 11
## 8 South Asia General 11
## 9 Middle East & North Africa General 9
## 10 Middle East & North Africa Bulk 4
ggplot(top5_port_typeR, aes(x = REGION, y = number_of_ports, fill = Type)) +
geom_col() +
coord_flip() +
labs(
title = "General vs. Bulk Ports: Top 5 Regions",
x = "Region",
y = "Number of Ports",
fill = "Port Type"
)
## Top 5 Countries
country_ports <- major_ports %>%
group_by(Country) %>%
summarize(number_of_ports = n()) %>%
arrange(desc(number_of_ports))
print(paste("The top 5 countries by number of major ports are:"))
## [1] "The top 5 countries by number of major ports are:"
head(country_ports, 5)
## # A tibble: 5 × 2
## Country number_of_ports
## <chr> <int>
## 1 IND 15
## 2 BRA 14
## 3 PHL 10
## 4 VNM 7
## 5 COL 6
# 1. The distribution of major international ports varies across regions. Latin America & Caribbean has the most major ports with 49, followed by Sub-Saharan Africa, then East Asia & Pacific.
# 2. In terms of port distribution across countries: India has the most major ports, followed by Brazil, then Philippines.
# 3.The number of General and Bulk ports is generally similar across the top five regions, except in the Middle East & North Africa, where there are more General ports than Bulk ports.