3.8 Run a remote script to make an interactive map

I’ve posted most of the data files from this book in a public repository on GitHub. Soon we’ll create a new RStudio project for all these files. For now, though, I’d like you to run one file from that “repo” at https://raw.githubusercontent.com/smach/R4JournalismBook/master/03_map.R . If that’s somewhat onerous to type, go to the bit.ly link http://bit.ly/R4JournalismLinks and find and copy the URL under the Chapter 3 heading.

Then run

Figure 3.6: Interactive map of Starbucks locations.

and see what happens. Eventually, you should see an interactive map in your bottom-right RStudio Viewer pane, showing a few Starbucks in Atlanta, like the one in Figure 3.6. This is a national map, though – you can zoom out and see other areas of the U.S.

Before you use this to find a coffee shop near you, though, be warned that the latest available data file for Starbucks locations is from 2012. The point is to demonstrate making a cool interactive map with pop-ups, and I’ve found that the Starbucks data set tends to resonate in a crowd of journalists.

I also wanted to show you how to include code from an external file in your scripts. source("myfile") lets you run code from an external file in your current script, whether that file is somewhere else on your own system or a file that you’ve stored remotely.