Dams in Maine

Author: Jeff Walker

Updated: 2014-05-09

Exploration of the dams package.

Load Data

The data are downloaded using the extract_nid() function.

require(dams)
require(dplyr)
require(ggmap)
require(ggplot2)
require(scales)

if (file.exists("dams.Rdata")) {
    load(file = "dams.Rdata")
} else {
    dams <- extract_nid(sample_only = FALSE)
    save(dams, file = "dams.Rdata")
}

# extract dams in Maine
dams.me <- filter(dams, State == "ME")

Group by river

dams.river <- group_by(dams.me, River) %.% 
  summarise(Count=n(),
            Storage.Missing=sum(is.na(NID_Storage)),
            Storage=sum(NID_Storage, na.rm=TRUE))

Which rivers have the most number of dams?

dams.count <- dams.river %.%
  filter(Count>2) %.% 
  arrange(-Count) %.%
  mutate(River=ordered(River, levels=River))

ggplot(dams.count, aes(River, Count)) + 
  geom_bar(stat='identity') + 
  theme(axis.text.x=element_text(angle=90, hjust=1, vjust=0.5)) +
  labs(x='River', y='Number of Dams')

plot of chunk hist.count

Which rivers have the most number of dams?

dams.storage <- dams.river %.%
  filter(Storage > quantile(dams.river$Storage, probs=c(.9))) %.% 
  arrange(-Storage) %.%
  mutate(River=ordered(River, levels=River))

ggplot(dams.storage, aes(River, Storage)) + 
  geom_bar(stat='identity') + 
  scale_y_continuous(labels=comma) +
  theme(axis.text.x=element_text(angle=90, hjust=1, vjust=0.5)) +
  labs(x='River', y='Total Storage (acft)')

plot of chunk hist.storage

Prepare for Maps

map <- get_googlemap('maine', zoom=7, color='bw')
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=maine&zoom=7&size=%20640x640&maptype=terrain&sensor=false
## Google Maps API Terms of Service : http://developers.google.com/maps/terms
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=maine&sensor=false
## Google Maps API Terms of Service : http://developers.google.com/maps/terms
dams.me <- mutate(dams.me, 
    Year_Completed_Group=cut(Year_Completed, 
                             breaks=seq(1700, 2050, by=50),  
                             labels=paste(seq(1700, 2000, by=50), 
                                          seq(1750, 2050, by=50), 
                                          sep='-')))

Map of Dam Height

ggmap(map, extent='device') + 
  geom_point(aes(x=Longitude, y=Latitude, 
                 size=NID_Height, color=Year_Completed_Group), 
                 data=dams.me) +
  scale_size_area('Height (ft)') +
  scale_color_brewer('Year Completed', palette="YlGnBu")

plot of chunk map.height

Map of Dam Storage

ggmap(map, extent='device') + 
  geom_point(aes(x=Longitude, y=Latitude, 
                 size=NID_Storage, color=Year_Completed_Group), 
                 data=dams.me) +
  scale_size_area('Storage (acft)') +
  scale_color_brewer('Year Completed', palette="YlGnBu")

plot of chunk map.storage

Map of Dam Discharge

ggmap(map, extent='device') + 
  geom_point(aes(x=Longitude, y=Latitude, 
                 size=Max_Discharge, color=Year_Completed_Group), 
                 data=dams.me) +
  scale_size_area('Max Discharge (cfs)') +
  scale_color_brewer('Year Completed', palette="YlGnBu")

plot of chunk map.q

Where are the dams on the Androscoggin?

ggmap(map, extent='device') + 
  geom_point(aes(x=Longitude, y=Latitude, 
                 size=NID_Height, color=Year_Completed_Group), 
             data=dams.me %.% filter(River=="ANDROSCOGGIN RIVER")) +
  scale_size_area('Height (ft)') +
  scale_color_brewer('Year Completed', palette="YlGnBu", drop=FALSE)

plot of chunk map.androscoggin

Where are the dams built before 1800?

ggmap(map, extent='device') + 
  geom_point(aes(x=Longitude, y=Latitude), 
             data=dams.me %.% filter(Year_Completed<=1800),
             color='red', size=4)

plot of chunk map.1800