library(sf)
## Linking to GEOS 3.13.1, GDAL 3.11.4, PROJ 9.7.0; sf_use_s2() is TRUE
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.6
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ ggplot2 4.0.2 ✔ tibble 3.3.1
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.2
## ✔ purrr 1.2.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
library(scales)
##
## Attachement du package : 'scales'
##
## L'objet suivant est masqué depuis 'package:purrr':
##
## discard
##
## L'objet suivant est masqué depuis 'package:readr':
##
## col_factor
chemin = "C:/Users/Valentin/Desktop/Python_geo_space/ne_110m_admin_0_countries"
monde = st_read(chemin)
## Reading layer `ne_110m_admin_0_countries' from data source
## `C:\Users\Valentin\Desktop\Python_geo_space\ne_110m_admin_0_countries'
## using driver `ESRI Shapefile'
## Simple feature collection with 177 features and 168 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -180 ymin: -90 xmax: 180 ymax: 83.64513
## Geodetic CRS: WGS 84
st_crs(monde)
## Coordinate Reference System:
## User input: WGS 84
## wkt:
## GEOGCRS["WGS 84",
## DATUM["World Geodetic System 1984",
## ELLIPSOID["WGS 84",6378137,298.257223563,
## LENGTHUNIT["metre",1]]],
## PRIMEM["Greenwich",0,
## ANGLEUNIT["degree",0.0174532925199433]],
## CS[ellipsoidal,2],
## AXIS["latitude",north,
## ORDER[1],
## ANGLEUNIT["degree",0.0174532925199433]],
## AXIS["longitude",east,
## ORDER[2],
## ANGLEUNIT["degree",0.0174532925199433]],
## ID["EPSG",4326]]
View the data set
#glimpse(monde)
#colnames(monde)
#summary(monde)
Number of country by continent
pays_par_continent <- monde %>%
st_drop_geometry() %>% # Delete the geometry
group_by(CONTINENT) %>%
summarise(nb_pays = n()) %>%
arrange(desc(nb_pays))
print(pays_par_continent)
## # A tibble: 8 × 2
## CONTINENT nb_pays
## <chr> <int>
## 1 Africa 51
## 2 Asia 47
## 3 Europe 39
## 4 North America 18
## 5 South America 13
## 6 Oceania 7
## 7 Antarctica 1
## 8 Seven seas (open ocean) 1
Visualization
ggplot(pays_par_continent, aes(x = reorder(CONTINENT, nb_pays),
y = nb_pays, fill = CONTINENT)) +
geom_col(show.legend = F) +
coord_flip() +
labs(title = "Nombre de pays par continent en 2019",
x = "continent", y = "nombre de continent")
theme_sub_axis_bottom()
## <theme> Named list()
## @ complete: logi FALSE
## @ validate: logi TRUE
Most top 15 popular countries in the world in 2019
top_population <- monde %>%
st_drop_geometry() %>%
select(NAME,CONTINENT, POP_EST, GDP_YEAR) %>%
filter(! is.na(POP_EST)) %>%
arrange(desc(POP_EST)) %>%
head(15)
print(top_population)
## NAME CONTINENT POP_EST GDP_YEAR
## 1 China Asia 1397715000 2019
## 2 India Asia 1366417754 2019
## 3 United States of America North America 328239523 2019
## 4 Indonesia Asia 270625568 2019
## 5 Pakistan Asia 216565318 2019
## 6 Brazil South America 211049527 2019
## 7 Nigeria Africa 200963599 2019
## 8 Bangladesh Asia 163046161 2019
## 9 Russia Europe 144373535 2019
## 10 Mexico North America 127575529 2019
## 11 Japan Asia 126264931 2019
## 12 Ethiopia Africa 112078730 2019
## 13 Philippines Asia 108116615 2019
## 14 Egypt Africa 100388073 2019
## 15 Vietnam Asia 96462106 2019
Graphical of the top 15 most popular countries in the world
ggplot(top_population, aes(x = reorder(NAME, POP_EST),
y = POP_EST / 1e6, fill = CONTINENT)) +
geom_col() +
coord_flip() +
labs(title = "Les top 15 pays les plus peuplés
au monde en 2019",
y = "Population (en million)",
x = "Pays",
fill = "continent") +
scale_y_continuous(labels = comma) +
theme_test()
Surface for each country (km²)
Mollweid correct projection for each country
monde_moll <- st_transform(monde, crs = "ESRI:54009")
monde_moll$area_km2 <- as.numeric(st_area(monde_moll)) / 1e6
top_superficie <- monde_moll %>%
st_drop_geometry() %>%
select(NAME, CONTINENT, area_km2, GDP_YEAR) %>%
arrange(desc(area_km2)) %>%
head(15)
print(top_superficie)
## NAME CONTINENT area_km2 GDP_YEAR
## 1 Russia Europe 16953324 2019
## 2 Antarctica Antarctica 11990363 2013
## 3 Canada North America 9996089 2019
## 4 United States of America North America 9526449 2019
## 5 China Asia 9428688 2019
## 6 Brazil South America 8559708 2019
## 7 Australia Oceania 7719210 2019
## 8 India Asia 3157537 2019
## 9 Argentina South America 2790478 2019
## 10 Kazakhstan Asia 2726129 2019
## 11 Dem. Rep. Congo Africa 2338772 2019
## 12 Algeria Africa 2326082 2019
## 13 Greenland North America 2194714 2018
## 14 Mexico North America 1978172 2019
## 15 Saudi Arabia Asia 1928524 2019
PIB of he top 15 countries
top_gdp <- monde %>%
st_drop_geometry() %>%
select(NAME, CONTINENT, GDP_MD, ECONOMY) %>%
filter(!is.na(GDP_MD)) %>%
arrange(desc(GDP_MD)) %>%
head(15)
print(top_gdp)
## NAME CONTINENT GDP_MD ECONOMY
## 1 United States of America North America 21433226 1. Developed region: G7
## 2 China Asia 14342903 3. Emerging region: BRIC
## 3 Japan Asia 5081769 1. Developed region: G7
## 4 Germany Europe 3861123 1. Developed region: G7
## 5 India Asia 2868929 3. Emerging region: BRIC
## 6 United Kingdom Europe 2829108 1. Developed region: G7
## 7 France Europe 2715518 1. Developed region: G7
## 8 Italy Europe 2003576 1. Developed region: G7
## 9 Brazil South America 1839758 3. Emerging region: BRIC
## 10 Canada North America 1736425 1. Developed region: G7
## 11 Russia Europe 1699876 3. Emerging region: BRIC
## 12 South Korea Asia 1646739 4. Emerging region: MIKT
## 13 Australia Oceania 1396567 2. Developed region: nonG7
## 14 Spain Europe 1393490 2. Developed region: nonG7
## 15 Mexico North America 1268870 4. Emerging region: MIKT
Visualization
ggplot(top_gdp, aes(x = reorder(NAME, GDP_MD), y = GDP_MD / 1000, fill = CONTINENT)) +
geom_col() +
coord_flip() +
labs(title = "Les top 15 pays par PIB en 2019",
x = "Pays", y = "PIB (milliards USD)",
fill = "Continent") +
scale_y_continuous(labels = comma) +
theme_light()
PIB MAP
ggplot(monde) +
geom_sf(aes(fill = GDP_MD), color = "white", size = 0.1) +
scale_fill_viridis_c(
option = "turbo",
na.value = "grey100",
name = "PIB (M USD)",
labels = comma
) +
labs(title = "PIB mondial par continent en 2019",
caption = "Source : Natural Earth Data.com") +
theme_gray()