Last week I learned while listening to NPR that Texas is at the top when it comes to wind power production among all US states. While it is a suprising fact given that Texas is a conservative state and the article is an interesting read in itself, this led me to pull some data from US Department of Energy and create the map I have presented here.
library(leaflet)
library(maps)
library(rvest)
library(readxl)
library(htmltools)
# Download Data from http://widgets.nrel.gov/mea/wind-exchange/data/installed_wind_capacity_by_state.xls
dat <- read_excel("installed_wind_capacity_by_state.xls", skip=5)
red.dat <- dat[1:52,c(1,19)]
url.coord <- c("https://inkplant.com/code/state-latitudes-longitudes")
coord <- url.coord %>%
read_html() %>%
html_nodes(xpath='//*[@id="main_content_div"]/table') %>%
html_table()
coord <- coord[[1]]
colnames(coord) <- coord[1,]
coord <- coord[-1,]
coord[,2] <- as.numeric(coord[,2])
coord[,3] <- as.numeric(coord[,3])
wind.states <- merge(red.dat,coord)
names(wind.states)[2] <- "MW"
mapStates <- map("state", fill = TRUE, plot = FALSE)
wind.states %>%
leaflet(height= "600px", width = "900px") %>%
addTiles() %>%
addPolygons(data=mapStates,
color="black",
stroke = TRUE,
weight=0.5,
fillOpacity=0) %>%
addCircles(radius=10*wind.states$MW,
color="grey",
weight=1,
fillColor = "orange",
fillOpacity=0.8,
label= ~htmlEscape(paste(wind.states$State, as.character(wind.states$MW),"MW"))) %>%
setView(zoom=4, lat=39,lng=-95)