Skip to main content


Showing posts from March, 2017

More contour and density plots [stat_density2d() and hdrcde()] of Michigan lottery sales in Grand Rapids

After the prior post of a density map of lottery sales, I thought perhaps I had incorrectly passed on some arguments within ggplot for the use of stat_density2d().  So I looked back through the documentation for  stat_density2d()at .  The example in the documentation is the Old Faithful geyser data, which I recalled from other contour/density plot analyses in Antony Unwin's Graphical Data Analysis with R .   Unwin's discussion of density plots relies on both ggplot() and the hdrcde() packages.  The two packages use different engines for density estimation/contour lines, so perhaps it could be interesting to compare the two.  Let's start with the contour/density estimation in Unwin's book.  Unwin begins with a scatterplot and contour lines for Old Faithful, which shows three distinct clusters of eruptions:  ggplot(geyser, aes(duration, waiting)) + geom_point() +        geom_density2d() +         ggtitle("Old Faithful geyser eruption d

Locating Michigan Lottery Retailers with the U.S. Census Bureau Geocoder API in R, part 1

This post records the process of cleaning and geocoding U.S. address records. The addresses are official records of Michigan lottery retailers.   Michigan contracts with one of the multi-national gambling companies to run the State lottery, and participates in the multi-state Powerball lottery as well. The data described here are retailer based records of lottery sales from 2003 to 2016. The purpose of the geocoding was to explore the distribution of sales across the State and to prepare to merge the dataset with various Census Bureau measures of geographic place characteristics. Of course, there’s a lengthy literature on individual level correlates of lottery ticket purchases , but I have been curious about where retailers tend to cluster throughout cities and townships in the State.  In what follows I describe the process of geocoding latitude and longitude coordinates — as well as U.S. Census geographies – of Michigan lottery retailers. The lottery sales data were provided to