In this assignment, we explored the geographic data of certain health care providers in the greater Spokane area
First we downloaded the necessary packages
library(ggplot2)
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.4.2
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyr)
## Warning: package 'tidyr' was built under R version 3.4.2
library(datasets)
library(gudatavizfa17)
library(htmlwidgets)
## Warning: package 'htmlwidgets' was built under R version 3.4.2
suppressMessages(library(ggmap))
## Warning: package 'ggmap' was built under R version 3.4.2
library(leaflet)
## Warning: package 'leaflet' was built under R version 3.4.2
Next, we subsetted the data set to only include the providers who focus on nephrology, internal medicine, and gastroenterology.
providerspokanesub <- subset(providerspokane, Provider.Type == "Nephrology" | Provider.Type == "Internal Medicine" | Provider.Type == "Gastroenterology", select=National.Provider.Identifier:Average.Medicare.Standardized.Amount)
Next we connected the combined address information to latitude and longitude information
latlon=function(providerspokanesub,Address){
locs=geocode(as.character(unique(providerspokanesub[,"Address"])))
locs$address=unique(providerspokanesub[,Address])
providerspokanesub$latitude=locs$lat[ match(providerspokanesub[,Address],locs$address)]
providerspokanesub$longitude=locs$lon[ match(providerspokanesub[,Address],locs$address)]
return(providerspokanesub)
}
providerspokanesmart=whatislatlon(providerspokanesub,"Address")
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=104%20W%205TH%20AVE%20STE%20200W%20%20SPOKANE%20WA%20992044803&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=910%20W%205TH%20AVE%20STE%20700%20%20SPOKANE%20WA%20992042967&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=820%20S%20MCCLELLAN%20#LL10%20SPOKANE%20WA%2099204&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=406%20E%20ROWAN%20AVE%20SUITE%20200%20SPOKANE%20WA%20992071243&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=820%20S%20MCCELLAN%20#LL10%20SPOKANE%20WA%2099204&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=400%20E%205TH%20AVE%20%20SPOKANE%20WA%20992021334&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=800%20W%205TH%20AVE%20%20SPOKANE%20WA%20992042803&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=910%20W%205TH%20AVE%20STE%20501%20%20SPOKANE%20WA%20992042966&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=610%20S%20SHERMAN%20ST%20SUITE%20201%20SPOKANE%20WA%20992021359&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=610%20S%20SHERMAN%20ST%20SUITE%20201%20SPOKANE%20WA%20992021342&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=1215%20N%20MDDONALD%20RD%20STE%20101%20SPOKANE%20WA%2099216&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=406%20E%20ROWAN%20AVE%20SUITE%20200%20SPOKANE%20WA%20992071201&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=3919%20N%20MAPLE%20ST%20%20SPOKANE%20WA%20992051349&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=316%20W%20BOONE%20AVE%20SUITE%20757%20SPOKANE%20WA%20992012354&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=5633%20N%20LIDGERWOOD%20ST%20%20SPOKANE%20WA%20992081224&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=820%20S%20MCCLELLAN%20ST%20STE%20200%20%20SPOKANE%20WA%20992042456&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=105%20W%208TH%20AVE%20SUITE%207060%20SPOKANE%20WA%20992042302&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=105%20W%208TH%20AVE%20SUITE%206010%20SPOKANE%20WA%20992042302&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=212%20E%20CENTRAL%20AVE%20SUITE%20440%20SPOKANE%20WA%20992086291&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=212%20E%20CENTRAL%20AVE%20STE.%20440%20SPOKANE%20WA%20992086291&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=801%20W%205TH%20AVE%20STE%20407%20SPOKANE%20WA%20992042823&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=910%20W%205TH%20AVE%20701%20SPOKANE%20WA%20992042966&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=101%20W%208TH%20AVE%20%20SPOKANE%20WA%20992042307&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=101%20W%208TH%20AVE%20PROVIDENCE%20MEDICAL%20GROUP%20SPOKANE%20WA%20992042307&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=3016%20E%2057TH%20AVE%20#24%20SPOKANE%20WA%20992237036&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=104%20W%205TH%20AVE%20SUITE%20200W%20SPOKANE%20WA%20992044880&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=910%20W%205TH%20AVE%20SUITE%20501%20SPOKANE%20WA%20992042966&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=316%20W%20BOONE%20AVE%20STE%20757%20SPOKANE%20WA%20992012364&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=6120%20N%20MAYFAIR%20ST%20%20SPOKANE%20WA%20992081033&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=910%20W%205TH%20AVE%20STE%20501%20CAPITAL%20CITY%20GASTROENTEROLOGY,%20PC%20SPOKANE%20WA%20992042967&sensor=false
## Warning: geocode failed with status ZERO_RESULTS, location = "910 W 5TH AVE
## STE 501 CAPITAL CITY GASTROENTEROLOGY, PC SPOKANE WA 992042967"
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=104%20W%205TH%20AVE%20STE%20400W%20%20SPOKANE%20WA%20992044800&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=104%20W%205TH%20AVE%20SUITE%20200W%20SPOKANE%20WA%20992044839&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=605%20E%20HOLLAND%20AVE%20SUITE%20101%20SPOKANE%20WA%20992182225&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=610%20S%20SHERMAN%20ST%20STE%20201%20SPOKANE%20WA%20992021359&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=820%20S.%20MCCLELLAN%20ST%20STE%20200%20SPOKANE%20WA%20992042456&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=105%20W%208TH%20AVE%206010%20SPOKANE%20WA%20992042302&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=820%20S%20MCCLELLAN%20#1110%20SPOKANE%20WA%2099204&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=7209%20S.%20SOUTH%20MEADOWS%20RD%20%20SPOKANE%20WA%2099223&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=105%20W.%208TH%20AVENUE%20SUITE%20550%20SPOKANE%20WA%20992042341&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=801%20W%205TH%20AVE%20SUITE%20622%20SPOKANE%20WA%20992042823&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=105%20W%208TH%20AVE%20SUITE%201000%20SPOKANE%20WA%20992042302&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=820%20S%20MCCLELLAN%20ST%20SUITE%20426%20SPOKANE%20WA%20992042446&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=820%20S%20MCCLELLAN%20SUITE%20200%20SPOKANE%20WA%2099204&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=105%20W%208TH%20AVE%20SUITE%206050%20SPOKANE%20WA%20992042302&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=6002%20N%20LIDGERWOOD%20ST%20%20SPOKANE%20WA%20992081124&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=801%20W%205TH%20AVE%20STE%20309%20%20SPOKANE%20WA%20992042841&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=104%20W%205TH%20AVE%20SUITE%20200%20W%20SPOKANE%20WA%20992044880&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=108%20N%20WASHINGTON%20ST%20SUITE%20405%20SPOKANE%20WA%20992015003&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=910%20W%205TH%20AVE%20STE%20501%20%20SPOKANE%20WA%20992042967&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=105%20W%208TH%20AVE%20SUITE%207050%20SPOKANE%20WA%20992042302&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=1111%20E%20WESTVIEW%20CT%20STE%20B%20SPOKANE%20WA%20992181376&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=105%20W%208TH%20AVE%20SUITE%206010%20SPOKANE%20WA%20992042341&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=322%20W%20NORTH%20RIVER%20DR%20%20SPOKANE%20WA%20992013208&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=910%20W%205TH%20AVE%20STE%20900%20%20SPOKANE%20WA%20992042948&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=801%20W%205TH%20AVE%20SUITE%20509%20SPOKANE%20WA%20992042823&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=104%20W%205TH%20AVE%20SUITE%20200%20W%20SPOKANE%20WA%20992044839&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=105%20W%208TH%20AVE%20STE%207060%20SPOKANE%20WA%20992042302&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=5921%20N%20MARKET%20ST%20%20SPOKANE%20WA%20992082484&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=624%20E%20FRONT%20ST%20%20SPOKANE%20WA%20992022139&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=4102%20S%20REGAL%20ST%20SUITE%20101%20SPOKANE%20WA%20992237737&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=6120%20N%20MAYFAIR%20ST%20SUITE%20101%20SPOKANE%20WA%20992081033&sensor=false
## .Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=2713%20N%20ARGONNE%20RD%20%20SPOKANE%20WA%20992122239&sensor=false
Here we created the base location for our maps
location=c(-117.4281,47.6566)
map=get_map(location=location,maptype="roadmap",source="google",zoom=11)
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=47.6566,-117.4281&zoom=11&size=640x640&scale=2&maptype=roadmap&language=en-EN&sensor=false
spokanemap=ggmap(map)
print(spokanemap)

Here is our static map of the location of the three provider types. The dots on the locations are colored by the provider type.
spokanemap=spokanemap+geom_point(data=providerspokanesmart,
aes(longitude,latitude,color=Provider.Type),size=3)
print(spokanemap)
## Warning: Removed 17 rows containing missing values (geom_point).

spokanemap+theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text = element_blank(),axis.title = element_blank(),
axis.ticks = element_blank())
## Warning: Removed 17 rows containing missing values (geom_point).

providerspokanesmart$Name <- paste(providerspokanesmart$First.Name.of.the.Provider, providerspokanesmart$Middle.Initial.of.the.Provider,providerspokanesmart$Last.Name.Organization.Name.of.the.Provider)