library(wbstats)
The WB can be search with a single word or multiple words. For example searching for unemployment information.
# Search WB API
unemployment_search <- wbsearch(pattern = "unemployment")
datatable(data = unemployment_search,
options = list(scrollX = T), # Gives acces to scroll on the X axis.
caption = "Unemployment")
This is how to search the WB with multiple criteria.
# Multiple search words
multiple_search <- wbsearch(pattern = "poverty|unemployment|employment")
datatable(data = multiple_search ,
options = list(scrollX = T), # Gives acces to scroll on the X axis.
caption = "multiple_search")
There are two different ways of getting the World Bank data. The second way is using the WDI package.
library(WDI)
Create a New Cache
new_wb_cache <- wbcache()
Search World Bank Indicators
WDIsearch('gdp')
# For multiple searches.
WDIsearch('gdp.*capital.*constant')
wb_dat <- wb(indicator = c("NY.GDP.PCAP.KD", "SP.DYN.LE00.IN", "SP.DYN.IMRT.IN"))
unemploy <- wbsearch(pattern = "unemployment", # Word to be match
fields = c("indicator", "indicatorDesc"), # Column names through which to search, i.e.
extra = FALSE)
education <- wbsearch(pattern = "education")
world_geo <- rnaturalearth::ne_countries(scale = 50, returnclass = "sf")
popa <- wb(country = "MX",
indicator = "ccx_yaurr_pop_tot",
mrv = 20)
pop_geo <- left_join(world_geo, pop_data, by = c("iso_a2" = "iso2c"))
v<- wb(indicator = "NY.GDP.MKTP.CD", startdate = 2000, enddate = 2019)
B<- wb(country = "all", # You can select specific country, or countries by c(USA, MXN, etc.)
indicator = "NY.GDP.MKTP.CD", # You need to know indicator name.
startdate = 2000, # 2016M01 for months
enddate = 2018, # mrv can be use for the last 20 years, mrv = 20
return_wide = FALSE,
gapfill,
freq,
cache,
lang = c("en", "es", "fr", "ar", "zh"),
removeNA = TRUE,
POSIXct = FALSE,
include_dec = FALSE,
include_unit = FALSE,
include_obsStatus = FALSE,
include_lastUpdated = FALSE)
OECD has a R library to get data straight from OECD data bases into your R consul.
library(OECD)
The first thing to do is to get the data list. This would create the data set of the OECD
# Code for getting data OECD data list.
datalist <- get_datasets()
# Creates Data table
datatable(data = datalist,
options = list(scrollX = T), # Gives acces to scroll on X Axis
caption = "DATALIST")
Search the data set you just created with get_datasets
# Search codes and discriptions of available OECD series.
unemployment = search_dataset("unemployment", data = datalist)
unemployment
## # A tibble: 7 x 2
## id title
## <fct> <fct>
## 1 DUR_I Incidence of unemployment by duration
## 2 DUR_D Unemployment by duration
## 3 AVD_DUR Average duration of unemployment
## 4 AEO2012_CH6_FI~ Figure 4: Youth and adult unemployment
## 5 AEO2012_CH6_FI~ Figure 29: Youth employment and unemployment by education and~
## 6 AEO2012_CH6_FI~ Figure 19: The trade off between vulnerable employment and un~
## 7 NRR Net Replacement Rates in unemployment
The main function in the OECD package in r is get_dataset.
df <- get_dataset("EO78_TRADE", # a string with the code for the desired data set
filter = list("DEU", "FRA"),
start_time = 2008, end_time = 2015)
get_data_structure() # Get the data structure of a data set.
browse_metadata() # Browse the metadata related to a series.
get_dataset() # Download OECD data sets.
library(tidycensus) # you need api key and setting it up.
For the US Census you will need to get a API key. To get an API key go to the US census website.
# Get the data from the US Census
LA <- get_acs(geography = "tract",
variables = "B25077_001", #Median value (dollars). HOUSEHOLDS
state = "CA",
county = "Los Angeles County",
geometry = TRUE,
cache_table = TRUE) # For faster results.
# Plots the data
ggplot(LA, aes(fill = estimate)) + geom_sf() #This will map varibles.
The Code below would gather different
# Many Variables. This is whats running the program.
racevars <- c(White = "P005003", #Total Population
Black = "P005004", # Total Population
Asian = "P005006",# Total Population
Hispanic = "P004003") # Total Population
# Second Part. Use the above recevars value.
LosAngeles <- get_decennial(geography = "tract",
variables = racevars, # This is where to add the variables created.
state = "CA",
county = "Los Angeles",
geometry = TRUE,
summary_var = "P001001",
cache_table = TRUE) # For faster results.)
There are different ways of mapping in R. One way is using the code below.
# Will Map it
LosAngeles %>%
mutate(pct = 100 * (value / summary_value)) %>%
ggplot(aes(fill = pct)) +
facet_wrap(~variable) +
geom_sf(color = NA) +
coord_sf(crs = 26915) +
scale_fill_viridis_c()
library(Quandl) # For Financial data gathering.
oil <- Quandl('NSE/OIL', type = "xts")
datatable(data = oil,
options = list(scrollX = T), # Gives acces to scroll on the X axis.
caption = "Oil")
plot(oil$Open)
library(gapminder)
library(quantmod)
library(acs)