Archive | R RSS for this section

Cool R packages I found today

Well, two packages, at least. Having not posted in well… forever… this is a decent move back into the world of blogging (which is far harder in 2018 than it was in, say, 2009.)

I have been working on Shiny based mapping apps recently and found the Zip Radius Package potentially convenient. I even made a map of zip codes and population within 100 miles of 48104.


The fieldRS package provides a convenient way of classifying and mapping remote sensing data, which will be extremly handy when doing the snake project, for example. An open question was how to access localized risk based on topography and landuse. I had no convenient way of assessing this at the time.



Mapmaking with ggmap

I am always looking for free alternatives to ArcGIS for making pretty maps. R is great for graphics and the new-to-me ggmap package is no exception.

I’m working with some data from Botswana for a contract and needed to plot maps for several years of count based data, where the GPS coordinates for facilities were known. ArcGIS is unwieldy for creating multiple maps of the same type of data based on time points, so R is an ideal choice…. the trouble is the maps I can easily make don’t look all that good (though with tweaking can be made to look better.)

ggmap offered me an easy solution. It downloads a topographic base map from Google and I can easily overlay proportionally sized points represent counts at various geo-located points. This is just a map of Botswanan health facilities (downloaded from Humanitarian Data Exchange) with the square of counts chosen from a normal distribution. The results are rather nice.



#read in grographic extent and boundary for bots
btw <- admin<-readOGR(“GIS Layers/Admin”,”BWA_adm2″) #from DIVA-GIS

# fortify bots boundary for ggplot
btw_df <- fortify(btw)

# get a basemap
btw_basemap <- get_map(location = “botswana”, zoom = 6)

# get the hf data<-read.csv(“BotswanaHealthFacilitiesOpenStreetMap.csv”)
# create random counts$Counts<-round((rnorm(112,mean=10,sd=5))^2,0)

# Plot this dog
ggmap(btw_basemap) +
geom_polygon(data=btw_df, aes(x=long, y=lat, group=group), fill=”red”, alpha=0.1) +
geom_point(, aes(x=X, y=Y, size=Counts, fill=Counts), shape=21, alpha=0.8) +
scale_size_continuous(range = c(2, 12), breaks=pretty_breaks(5)) +
scale_fill_distiller(breaks = pretty_breaks(5))

%d bloggers like this: