Plotting California earthquake data!

Earthquakes have been in the news lately - in particular, two very strong earthquakes that recently hit California. Exactly where did they hit? ... Let's plot it on a map!

But before we get busy analyzing the California data, here's a picture to get you in the mood for studying things like earthquakes, faults, and tectonic plate movement. This is a photo my friend Eva took while on a trip to to New Zealand's South Island:

Raw Data

Now let's analyze that California data! First I went to the NOAA page that allows me to select and download earthquake data. I specified that I wanted 2019 data for California, as follows:

And at the bottom of the form, I selected the box to return the data as a simple text file, with tab-separated columns of data. I clicked the 'Search Database' button, and it downloaded the results in a file called 'results' (which I renamed as california_earthquakes_2019.tsv).

Importing the data

All of the date & time values were stored as UTC values. I decided to convert them to local California time. Since all the year/month/day/hour/minute/second values were stored in separate variables, I had to build up strings for the date and time, and create proper SAS date and time variables, and then convert that to local time (in the final step below).

Plotting coordinates on a map

With the new Proc SGmap, it is very simple to plot markers on a map at lat/long coordinates, using minimal code. The following code plots a small solid marker, with a semi-transparent circle around it, on an OpenStreetmap.

SGmap automatically 'zooms in' on the smallest area that contains all the lat/long coordinates being plotted. In this particular case, both earthquakes are very close together, and therefore the map is a very small area - so small, that there aren't really enough surrounding landmarks for most people to recognize the area.

A trick I often use, to make sure the map includes a larger area, or a fixed area, is to also overlay a border outline on the map (such as a country, state, or county outline), as an empty choropleth map. In this case, since I'm interested in California earthquakes, I overlay the state outline of California.

Now I can see where the earthquakes occurred, in relation to the state of California (see the darker outline of California on the map). And the Openstreetmap even shows some cities and roads. But when it comes to data such as earthquakes, I would also like to see an indication of the "lay of the land" - such as mountains and valleys. With SGmap, you can use maps from the ESRI map server, and several of those maps show the kind of terrain detail I want. The code below shows how to use an ESRI map, rather than Openstreetmap. (Here's a link to the complete SAS code used to create all the samples in this blog post.)

About Author

Robert has worked at SAS for over a quarter century, and his specialty is customizing graphs and maps - adding those little extra touches that help them answer your questions at a glance. His educational background is in Computer Science, and he holds a BS, MS, and PhD from NC State University.

About

Welcome to Graphically Speaking, a blog focused on the usage of ODS Graphics for data visualization in SAS. The blog will cover topics related to the Statistical Graphics procedures, the Graph Template Language and the ODS Graphics Designer.

For more in-depth information on using the ODS Graphics system, please check out the following SAS Press books :