I have been working on a simple R function to take latitude and longitude of points of interest, and text for pop-up labels, and produce an interactive online map. Interactive graphics are incredibly useful in getting people interested in your work and communicating your data effectively, but very few statisticians / data analysts have the skills needed to make them. My aims are in this order:
- give you a really easy way of making an online interactive map
It is at a very early stage, and I have a long list of things to do to improve it, but I would value any feedback on it. You can download it from here and then load it into R by typing:
The code is at Github if you want to see how it is made and collaborate. My to-do list is there too. I encourage anyone interested in this to join me and contribute so we can make a whole suite of simple R2JS visualization functions!
Here’s how it was made:
lat<-c(51.426694, 51.523242, 54.008727, 54.977433)
long<-c(-0.174015, -0.119959, -2.785206, -1.607604)
label<-c("St George's Hospital",
"UCL Institute of Child Health <br> Harvard GCSRT venue",
"University of Northumbria <br> RSS 2013 venue")
The defaults have been retained for some other arguments: map.lat and map.long, which center the map, map.zoom, which zooms in and out, and popup, which is a Boolean vector of the same length as lat, long and label, which is TRUE if you want a popup and FALSE if you don’t.
There are some neat R functions out there to make latitude and longitude from various co-ordinate systems. If you need to look up latitude and longitude for a specific few points, this website is handy. Notice how the line breaks in the popups are produced by <br>, which an HTML tag. Want to format your text inside the popup? You can simply add HTML tags to the character vector called ‘label’. If you don’t know about HTML tags, visit this page and you’ll soon be <impressive>a web coding fiend</impressive>.
Remember that any vectors you supply to the arguments ‘lat’, ‘long’, ‘label’ and ‘popup’ will be recycled R-style if they are not the same length, with potentially disastrous results in your map! The function returns nothing at present, but you can easily change it to select from the various parts of text written to the file in a return command if that would be useful for you.