options(repos = c(CRAN = "https://cran.r-project.org"))
#install.packages ("WDI")
library(WDI)
install.packages ("wbstats")
##
## The downloaded binary packages are in
## /var/folders/88/qd2dwk153fsbwf8l96r05ngc0000gn/T//Rtmp2HWLqc/downloaded_packages
library(wbstats)
install.packages ("tidyverse")
##
## The downloaded binary packages are in
## /var/folders/88/qd2dwk153fsbwf8l96r05ngc0000gn/T//Rtmp2HWLqc/downloaded_packages
library(tidyverse)
install.packages ("ggplot2")
##
## The downloaded binary packages are in
## /var/folders/88/qd2dwk153fsbwf8l96r05ngc0000gn/T//Rtmp2HWLqc/downloaded_packages
library(ggplot2)
gdp_mexico <- wb_data(country = "MX", indicator = "NY.GDP.PCAP.CD", start_date = 1900, end_date=2024)
# (ISO3166-2 country codes)
summary(gdp_mexico)
## iso2c iso3c country date
## Length:64 Length:64 Length:64 Min. :1960
## Class :character Class :character Class :character 1st Qu.:1976
## Mode :character Mode :character Mode :character Median :1992
## Mean :1992
## 3rd Qu.:2007
## Max. :2023
## NY.GDP.PCAP.CD unit obs_status footnote
## Min. : 359.5 Length:64 Length:64 Length:64
## 1st Qu.: 1431.5 Class :character Class :character Class :character
## Median : 4017.8 Mode :character Mode :character Mode :character
## Mean : 5132.1
## 3rd Qu.: 8959.9
## Max. :13926.1
## last_updated
## Min. :2024-06-28
## 1st Qu.:2024-06-28
## Median :2024-06-28
## Mean :2024-06-28
## 3rd Qu.:2024-06-28
## Max. :2024-06-28
head(gdp_mexico)
## # A tibble: 6 × 9
## iso2c iso3c country date NY.GDP.PCAP.CD unit obs_status footnote
## <chr> <chr> <chr> <dbl> <dbl> <chr> <chr> <chr>
## 1 MX MEX Mexico 1960 360. <NA> <NA> <NA>
## 2 MX MEX Mexico 1961 378. <NA> <NA> <NA>
## 3 MX MEX Mexico 1962 393. <NA> <NA> <NA>
## 4 MX MEX Mexico 1963 424. <NA> <NA> <NA>
## 5 MX MEX Mexico 1964 486. <NA> <NA> <NA>
## 6 MX MEX Mexico 1965 511. <NA> <NA> <NA>
## # ℹ 1 more variable: last_updated <date>
tail(gdp_mexico)
## # A tibble: 6 × 9
## iso2c iso3c country date NY.GDP.PCAP.CD unit obs_status footnote
## <chr> <chr> <chr> <dbl> <dbl> <chr> <chr> <chr>
## 1 MX MEX Mexico 2018 10130. <NA> <NA> <NA>
## 2 MX MEX Mexico 2019 10435. <NA> <NA> <NA>
## 3 MX MEX Mexico 2020 8896. <NA> <NA> <NA>
## 4 MX MEX Mexico 2021 10363. <NA> <NA> <NA>
## 5 MX MEX Mexico 2022 11477. <NA> <NA> <NA>
## 6 MX MEX Mexico 2023 13926. <NA> <NA> <NA>
## # ℹ 1 more variable: last_updated <date>
ggplot(gdp_mexico, aes(x = date, y = NY.GDP.PCAP.CD)) + geom_point()
ggplot(gdp_mexico, aes(x = date, y = NY.GDP.PCAP.CD)) + geom_col()
ggplot(gdp_mexico, aes(x = date, y = NY.GDP.PCAP.CD)) + geom_point(fill = "cyan") + geom_col(color = "blue") + labs(title="Producto Interno Bruto en Mexico (US Per Capita)", x = "Año", y = "PIB")
# Informacion de varios Paises
gdp_varios <- wb_data(country = c("MX","EC","CL"), indicator = "NY.GDP.PCAP.CD", start_date= 1900, end_date = 2024)
ggplot(gdp_varios, aes(x = date, y = NY.GDP.PCAP.CD, color = country)) + geom_point()