Mapping GDP
In this tutorial, we'll use the R library to extract a dataset and map the values in leaflet. Before we get started, you'll need to register for a BEA (API key). It'll be needed to make API requests.
key = "your-BEA-key-goes-here"
Now we can call the eu.us.opendata library and get started with extracting data.
library(eu.us.opendata)
Of course if we want to search for a specific series such as Gross Domestic Product (GDP) by state or equivalent area, we could use the searchRel() method. But if we trust the accuracy of search, we can go straight to extracting the data by specifying lucky = T.
searchRel("state gross domestic product", asHTML = T)
dataset<-getRel("state gross domestic product", beaKey = key, lucky = T)
## [1] "Search duration: 0.044s"
## [1] "Top match for 'state gross domestic product': 100% = Annual GDP by State/NUTS 2"
## [1] "A total of 7830 records were retrieved."
## [1] "EU = 6690, US = 1140"
This library comes with tools to produce interactive maps using the geoMap() function. This can repackage the data into a leaflet.js map for a given year, a shapefile joined with a specific year of data, or a shapefile with a column for each year of data.
geoMap(dataset, 2010)
## [1] "Identifying geographic levels"
## [1] "Dataset: Annual GDP by State/NUTS 2"
## [1] "US Geography: State"
## [1] "EU Geography: NUTS2"