The Global Earthquake Desktop

[This article was first published on rare earth, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

One of the first things I do over coffee each morning is scroll through the USGS earthquake RSS feeds.  In the era of free data and open source computing I asked myself, “Wouldn’t it be better to visualize all of the earthquakes around the world rather than read a list?”  To that end I used the R maps package, some data mining, and a cron task to create a live desktop wall paper of global earthquakes.  Here’s how.

Below is the final map to be used as the desktop wall paper (click to enlarge).  To create the image we’ll need to pull a list of earthquake locations and magnitudes from the web, plot those earthquakes on the map, and save the output to an image file.  From there we can automate the task to update and display a new image on the desktop each day.

The U.S. Geological Survey (USGS) provides feeds and data catalogs of the latest earthquakes, which can be found here.  For our purposes we’ll use the data for all earthquakes greater than magnitude 2.5 that have occurred over the last seven days.

The maps package in R is great for producing simple maps of data and coding up our earthquake map is pretty straightforward.  Here’s the code.

From there you can simply set the image to your desktop wallpaper as you would any other image.  With a little extra work, however, you can setup you Mac to run the R script and update the map each day with the most recent earthquakes.  The first step is to create a shell command file in your favorite text editor and save the file with a name like “worldeq.command”.

There’s only three lines of code: The first line runs the R script to generate the global map of earthquakes. The second line of code sets the desktop background to the new image. The third line, killall Dock, refreshes the Dock to display the most recent image.

There you have it. Run the shell command anytime you’d like to update the desktop, add it to your login items to refresh the map each time you log in, or set up a cron task to update the image on an hourly basis.

To setup a cron task to refresh the map every four hours do the following (Thanks to Jason Mulcahy for help with this part):
  1. In terminal bring up the crontab file in the Vim editor by typing: sudo crontab -e
  2. Enter you password.
  3. Type i to modify the file.  You should see –INSERT– at the bottom of the terminal. Enter everything below in line 4, making sure to correct the file path.
  4. * */4 * * * /Path/To/The/File/worldeq.command
  5. Type :w to write the above line of text to the file.
  6. Type :q to quit the editor.
  7. Verify that the changes were made by typing: sudo crontab -l

To leave a comment for the author, please follow the link and comment on their blog: rare earth. 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.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)