# Maps, Geocoding, and the R User Conference 2010

July 14, 2010
By

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The R User Conference 2010 is scheduled for July 20-23, 2010.  Wanna know where?

Although there are more sophisticated methods of mapping with R the maps package makes mapping activities straightforward.  A bit of XML and Google Geocoding is enough to highlight the location of this years conference (or any other location of interest to you).  If you prefer to see this in living color – you can view it at github.

getDocNodeVal=function(doc, path)
{
sapply(getNodeSet(doc, path), function(el) xmlValue(el))
}

gGeoCode=function(str)
{
library(XML)
doc = xmlTreeParse(u, useInternal=TRUE)
str=gsub(‘ ‘,’%20’,str)
lng=getDocNodeVal(doc, “/GeocodeResponse/result/geometry/location/lat”)
lat=getDocNodeVal(doc, “/GeocodeResponse/result/geometry/location/lng”)
c(lat,lng)
}

bullseyeEtc=function(str)
{
for (i in 1:10){points(loc[1],loc[2],col=heat.colors(10)[i],cex=i)}
for (i in 1:10){points(loc[1],loc[2],col=heat.colors(10)[i],cex=i*.5)}
title(main=’The R User Conference 2010′, sub=’July 20-23, 2010′)
mtext(“NIST: Gaithersburg, Maryland, USA”)
mtext(“http://user2010.org”,4)
}

loc=gGeoCode(‘100 Bureau Drive Gaithersburg, MD, 20899, USA’)

# World
map(‘world’, plot=TRUE, fill=TRUE);bullseyeEtc()

# USA
map(‘usa’, plot=TRUE, fill=TRUE);bullseyeEtc()

# State
map(‘state’,’Maryland’, plot=TRUE, fill=TRUE);bullseyeEtc()

UPDATE:  Thanks for the feedback in the comments below – there are a number of improvements suggested:
1)  Use URL Encode rather than just substituting out spaces.
2)  I ran this code without any problem on two machines – using R version 2.10.1 (2009-12-14) for Windows and XML version 2.8-1.  Other folks ran into problems with URL escape characters – but were able to replicate the functionality using the JSON package.  For more information…see the post at stackoverflow.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.