Created
April 1, 2014 19:37
-
-
Save hrbrmstr/9921419 to your computer and use it in GitHub Desktop.
March 2014 California Earthquakes via ggmap/ggplot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MAG DATE LOCAL-TIME LAT LON DEPTH | |
2.0 2014/03/31 07:21:17 33.916 -117.935 1.7 | |
2.0 2014/03/31 07:15:53 33.925 -117.898 1.9 | |
1.7 2014/03/31 07:10:39 33.903 -117.959 0.0 | |
1.5 2014/03/31 05:22:48 34.141 -117.462 7.1 | |
2.1 2014/03/31 04:41:22 33.961 -117.902 6.3 | |
1.3 2014/03/31 03:00:56 33.903 -117.954 0.0 | |
1.3 2014/03/31 01:26:57 33.915 -117.945 3.6 | |
1.5 2014/03/31 00:06:00 33.953 -117.919 7.3 | |
1.2 2014/03/30 22:55:01 33.956 -117.911 6.8 | |
1.5 2014/03/30 21:20:34 33.939 -117.915 2.4 | |
1.8 2014/03/30 21:07:37 34.350 -118.485 0.1 | |
1.4 2014/03/30 20:57:52 33.905 -117.950 0.1 | |
1.0 2014/03/30 18:42:20 34.099 -117.303 15.9 | |
2.4 2014/03/30 17:59:50 33.900 -117.958 0.6 | |
2.3 2014/03/30 17:58:01 33.909 -117.956 1.8 | |
2.0 2014/03/30 16:10:34 33.960 -117.884 3.4 | |
1.2 2014/03/30 13:57:06 34.266 -117.600 7.3 | |
1.6 2014/03/30 11:58:07 33.929 -117.914 3.4 | |
1.8 2014/03/30 11:13:23 33.915 -117.934 0.8 | |
1.4 2014/03/30 09:53:53 33.903 -117.962 1.1 | |
1.1 2014/03/30 09:37:02 33.928 -117.915 0.0 | |
1.9 2014/03/30 09:15:44 33.893 -117.957 0.8 | |
1.7 2014/03/30 09:13:21 33.917 -117.931 1.5 | |
2.7 2014/03/30 09:05:00 33.915 -117.945 0.4 | |
1.6 2014/03/30 08:41:57 34.983 -117.513 2.0 | |
1.3 2014/03/30 08:41:30 34.123 -117.453 8.2 | |
1.0 2014/03/30 06:28:57 34.183 -117.617 4.8 | |
1.7 2014/03/30 05:28:50 33.947 -117.908 2.0 | |
2.0 2014/03/30 04:57:09 33.898 -117.948 0.0 | |
1.3 2014/03/30 04:57:01 33.935 -117.910 6.6 | |
1.2 2014/03/30 02:14:07 33.932 -117.943 4.4 | |
1.1 2014/03/30 01:23:42 33.907 -117.958 1.0 | |
0.8 2014/03/30 01:15:39 33.938 -117.903 3.2 | |
2.5 2014/03/30 01:13:59 33.930 -117.916 0.2 | |
1.8 2014/03/30 00:43:54 33.910 -117.948 1.4 | |
1.1 2014/03/30 00:31:52 33.900 -117.961 2.2 | |
2.9 2014/03/29 23:31:49 33.904 -117.948 1.1 | |
3.2 2014/03/29 23:17:31 33.903 -117.937 0.0 | |
1.7 2014/03/29 22:53:53 33.897 -117.951 0.0 | |
3.3 2014/03/29 22:51:22 33.907 -117.954 1.9 | |
1.2 2014/03/29 22:33:21 33.902 -117.949 0.6 | |
2.5 2014/03/29 22:23:00 33.938 -117.900 1.6 | |
1.4 2014/03/29 22:17:29 33.961 -117.879 0.0 | |
2.6 2014/03/29 22:06:33 33.910 -117.949 1.9 | |
2.4 2014/03/29 22:00:07 33.950 -117.905 3.4 | |
1.1 2014/03/29 21:41:42 33.959 -117.902 3.8 | |
2.3 2014/03/29 21:10:11 33.902 -117.936 1.0 | |
1.2 2014/03/29 21:09:39 33.912 -117.946 1.8 | |
2.6 2014/03/29 20:48:20 33.915 -117.924 0.0 | |
1.2 2014/03/29 19:54:50 33.930 -117.941 5.4 | |
1.6 2014/03/29 18:34:26 33.927 -117.916 1.7 | |
1.3 2014/03/29 18:30:46 33.926 -117.899 4.4 | |
2.2 2014/03/29 17:58:18 34.112 -118.487 8.3 | |
1.8 2014/03/29 17:55:14 33.906 -117.947 0.1 | |
1.5 2014/03/29 17:24:09 33.961 -117.905 4.0 | |
1.3 2014/03/29 16:41:22 33.948 -117.910 6.5 | |
1.5 2014/03/29 16:26:31 33.905 -117.933 2.3 | |
1.1 2014/03/29 16:02:55 33.957 -117.913 7.2 | |
2.1 2014/03/29 16:00:19 33.962 -117.905 1.7 | |
1.3 2014/03/29 15:05:21 33.905 -117.945 2.0 | |
1.2 2014/03/29 14:54:06 33.955 -117.901 3.6 | |
1.2 2014/03/29 14:53:03 33.914 -117.949 2.7 | |
2.1 2014/03/29 14:36:12 33.964 -117.886 2.0 | |
2.0 2014/03/29 14:35:47 33.919 -117.937 1.4 | |
4.1 2014/03/29 14:32:45 33.961 -117.892 9.4 | |
1.9 2014/03/29 13:50:26 33.757 -117.531 3.9 | |
2.0 2014/03/29 13:16:57 33.926 -117.923 4.8 | |
1.3 2014/03/29 13:14:56 33.914 -117.914 1.9 | |
1.7 2014/03/29 11:10:03 33.914 -117.955 0.1 | |
2.1 2014/03/29 11:07:35 33.907 -117.944 0.1 | |
1.2 2014/03/29 10:42:52 34.032 -117.151 17.3 | |
2.2 2014/03/29 10:41:18 33.908 -117.942 0.0 | |
1.6 2014/03/29 10:38:58 33.935 -117.927 0.2 | |
1.6 2014/03/29 10:05:49 33.908 -117.947 0.8 | |
1.5 2014/03/29 09:29:16 33.900 -117.949 1.1 | |
1.4 2014/03/29 09:27:38 33.900 -117.969 1.6 | |
3.4 2014/03/29 09:02:06 33.905 -117.949 1.3 | |
2.1 2014/03/29 08:58:02 33.906 -117.956 0.4 | |
1.2 2014/03/29 08:29:28 33.917 -117.948 4.0 | |
1.7 2014/03/29 08:11:19 33.903 -117.952 0.8 | |
1.8 2014/03/29 08:10:45 33.901 -117.958 2.1 | |
2.3 2014/03/29 07:53:49 33.899 -117.950 1.0 | |
1.3 2014/03/29 07:53:18 33.893 -117.967 0.5 | |
2.4 2014/03/29 07:48:13 33.899 -117.963 3.9 | |
1.4 2014/03/29 07:37:18 33.915 -117.931 4.7 | |
1.3 2014/03/29 07:24:25 33.924 -117.908 4.8 | |
1.1 2014/03/29 06:54:02 34.196 -117.612 2.9 | |
1.4 2014/03/29 06:26:08 33.915 -117.942 2.5 | |
1.3 2014/03/29 05:54:07 33.908 -117.942 1.4 | |
1.3 2014/03/29 05:43:00 33.922 -117.935 2.6 | |
1.4 2014/03/29 05:25:44 33.909 -117.938 1.0 | |
2.5 2014/03/29 05:04:27 33.932 -117.904 0.1 | |
1.2 2014/03/29 04:53:16 33.910 -117.941 3.5 | |
1.4 2014/03/29 04:42:11 33.897 -117.961 2.0 | |
1.4 2014/03/29 04:32:35 33.925 -117.929 2.1 | |
1.3 2014/03/29 04:29:41 33.932 -117.917 3.6 | |
1.0 2014/03/29 04:29:08 33.916 -117.932 2.5 | |
2.4 2014/03/29 04:22:57 33.764 -117.515 1.3 | |
1.8 2014/03/29 04:15:25 33.895 -117.950 0.0 | |
1.7 2014/03/29 04:06:12 33.940 -117.907 2.5 | |
1.5 2014/03/29 04:03:24 33.931 -117.937 0.3 | |
1.4 2014/03/29 04:01:55 33.919 -117.922 4.5 | |
1.5 2014/03/29 03:48:26 33.929 -117.918 2.6 | |
1.1 2014/03/29 03:46:59 33.903 -117.941 0.6 | |
1.3 2014/03/29 03:38:58 33.937 -117.945 3.1 | |
1.1 2014/03/29 03:38:53 33.909 -117.938 1.8 | |
2.8 2014/03/29 03:31:51 33.911 -117.944 0.9 | |
1.6 2014/03/29 03:23:52 33.907 -117.951 0.0 | |
1.8 2014/03/29 03:07:58 33.926 -117.917 0.8 | |
1.1 2014/03/29 03:00:54 33.911 -117.941 0.2 | |
1.3 2014/03/29 02:54:42 33.934 -117.922 3.6 | |
2.6 2014/03/29 02:49:40 33.908 -117.952 0.3 | |
1.3 2014/03/29 02:48:05 33.940 -117.905 3.0 | |
1.4 2014/03/29 02:46:01 33.925 -117.920 2.4 | |
2.0 2014/03/29 02:41:30 33.901 -117.961 0.8 | |
1.1 2014/03/29 02:38:35 33.903 -117.962 0.0 | |
1.5 2014/03/29 02:31:34 33.898 -117.962 0.8 | |
1.0 2014/03/29 02:25:43 33.906 -117.938 0.2 | |
1.1 2014/03/29 01:51:22 33.912 -117.939 2.3 | |
1.0 2014/03/29 01:41:02 33.902 -117.945 1.5 | |
1.1 2014/03/29 01:40:01 33.897 -117.950 1.2 | |
2.3 2014/03/29 01:26:41 33.906 -117.951 0.2 | |
1.7 2014/03/29 01:23:54 33.899 -117.964 0.9 | |
1.3 2014/03/29 01:23:12 33.914 -117.935 1.8 | |
1.3 2014/03/29 01:03:46 33.940 -117.908 3.0 | |
1.3 2014/03/29 00:59:52 33.899 -117.957 2.2 | |
1.4 2014/03/29 00:50:41 33.893 -117.962 1.9 | |
1.5 2014/03/29 00:46:11 33.900 -117.962 0.0 | |
1.3 2014/03/29 00:45:55 33.937 -117.912 4.4 | |
1.5 2014/03/29 00:42:49 33.910 -117.945 0.0 | |
1.0 2014/03/29 00:39:22 33.942 -117.901 2.1 | |
1.1 2014/03/29 00:32:15 33.931 -117.918 2.1 | |
1.2 2014/03/29 00:25:04 33.915 -117.909 0.0 | |
2.4 2014/03/29 00:17:27 33.925 -117.920 0.0 | |
2.4 2014/03/29 00:17:27 33.964 -117.909 0.0 | |
1.2 2014/03/29 00:08:37 33.905 -117.945 0.3 | |
1.2 2014/03/29 00:02:12 33.896 -117.963 0.1 | |
1.6 2014/03/28 23:54:18 33.900 -117.956 0.4 | |
1.3 2014/03/28 23:43:40 33.928 -117.914 2.3 | |
2.3 2014/03/28 23:42:19 33.915 -117.941 0.0 | |
1.3 2014/03/28 23:40:21 33.897 -117.966 0.0 | |
1.5 2014/03/28 23:38:08 33.896 -117.959 0.1 | |
1.6 2014/03/28 23:25:05 33.911 -117.943 0.0 | |
2.1 2014/03/28 23:21:52 33.925 -117.924 0.8 | |
1.5 2014/03/28 23:19:25 33.907 -117.948 1.1 | |
1.2 2014/03/28 23:17:27 33.934 -117.913 2.7 | |
1.4 2014/03/28 23:16:10 33.917 -117.942 2.6 | |
1.3 2014/03/28 23:15:46 33.916 -117.921 1.0 | |
2.3 2014/03/28 23:12:45 33.904 -117.946 0.1 | |
2.3 2014/03/28 23:12:30 33.902 -117.955 0.5 | |
1.5 2014/03/28 23:11:43 33.933 -117.913 3.0 | |
1.8 2014/03/28 23:07:09 33.920 -117.935 0.2 | |
1.5 2014/03/28 23:01:20 33.921 -117.919 1.3 | |
1.1 2014/03/28 23:00:15 33.924 -117.932 2.8 | |
1.8 2014/03/28 22:50:46 33.908 -117.939 0.0 | |
1.4 2014/03/28 22:44:27 33.929 -117.900 0.7 | |
3.1 2014/03/28 22:37:14 33.922 -117.900 4.3 | |
1.4 2014/03/28 22:22:22 33.923 -117.919 2.4 | |
1.1 2014/03/28 22:19:07 33.913 -117.928 2.3 | |
1.2 2014/03/28 22:18:02 33.909 -117.943 1.4 | |
1.2 2014/03/28 22:06:40 33.898 -117.964 5.3 | |
2.6 2014/03/28 22:05:31 33.938 -117.909 2.4 | |
2.7 2014/03/28 22:05:31 33.934 -117.925 0.7 | |
2.4 2014/03/28 21:56:45 33.923 -117.923 0.5 | |
1.4 2014/03/28 21:55:44 33.910 -117.931 3.2 | |
2.7 2014/03/28 21:53:57 33.942 -117.910 1.3 | |
1.4 2014/03/28 21:50:37 33.899 -117.951 0.4 | |
1.3 2014/03/28 21:49:47 33.910 -117.934 0.1 | |
2.9 2014/03/28 21:47:13 33.932 -117.912 5.3 | |
2.7 2014/03/28 21:45:37 33.939 -117.904 1.3 | |
1.3 2014/03/28 21:44:34 33.908 -117.950 4.3 | |
1.7 2014/03/28 21:39:25 33.923 -117.911 3.3 | |
1.2 2014/03/28 21:38:20 33.916 -117.946 2.6 | |
1.7 2014/03/28 21:36:44 33.915 -117.923 0.1 | |
1.5 2014/03/28 21:35:23 33.909 -117.944 0.0 | |
2.0 2014/03/28 21:35:03 33.906 -117.937 2.0 | |
2.2 2014/03/28 21:32:13 33.911 -117.922 0.0 | |
3.6 2014/03/28 21:30:51 33.919 -117.924 0.1 | |
1.6 2014/03/28 21:30:28 33.928 -117.916 2.0 | |
1.4 2014/03/28 21:30:06 33.922 -117.906 2.1 | |
1.4 2014/03/28 21:29:28 33.928 -117.929 3.2 | |
1.1 2014/03/28 21:27:40 33.890 -117.962 4.1 | |
2.4 2014/03/28 21:19:54 33.918 -117.922 0.0 | |
1.8 2014/03/28 21:19:19 33.922 -117.930 2.3 | |
2.1 2014/03/28 21:18:01 33.925 -117.918 0.9 | |
1.8 2014/03/28 21:17:19 33.925 -117.928 2.5 | |
1.9 2014/03/28 21:16:28 33.917 -117.933 1.6 | |
2.0 2014/03/28 21:15:12 33.927 -117.900 2.1 | |
3.4 2014/03/28 21:11:53 33.924 -117.920 0.1 | |
5.1 2014/03/28 21:09:42 33.919 -117.944 7.5 | |
1.8 2014/03/28 21:08:56 34.217 -117.556 9.5 | |
2.1 2014/03/28 20:16:47 33.928 -117.923 2.1 | |
3.6 2014/03/28 20:03:39 33.923 -117.930 6.9 | |
1.6 2014/03/28 16:10:52 33.833 -117.495 1.2 | |
1.9 2014/03/28 10:35:55 34.158 -117.365 9.8 | |
0.9 2014/03/28 05:00:03 34.062 -117.271 19.2 | |
1.2 2014/03/28 03:39:54 34.136 -118.504 6.7 | |
1.3 2014/03/28 00:10:20 34.123 -118.492 8.7 | |
1.5 2014/03/27 22:46:17 34.168 -117.614 11.4 | |
1.4 2014/03/27 14:59:48 34.129 -118.488 7.5 | |
1.4 2014/03/27 11:31:31 34.374 -118.305 8.8 | |
1.4 2014/03/27 09:31:09 34.009 -117.174 14.9 | |
1.4 2014/03/27 04:21:56 34.123 -118.496 9.4 | |
1.1 2014/03/26 09:35:29 33.824 -117.489 0.0 | |
1.3 2014/03/25 12:27:49 33.846 -117.492 0.0 | |
1.0 2014/03/25 12:02:19 34.049 -117.222 14.1 | |
1.6 2014/03/25 10:36:56 34.119 -118.497 10.0 | |
1.4 2014/03/25 07:29:56 34.024 -117.211 16.3 | |
1.3 2014/03/25 02:53:33 34.195 -117.583 4.6 | |
1.8 2014/03/24 23:02:08 34.209 -117.579 9.9 | |
2.0 2014/03/24 15:24:58 33.754 -118.159 12.1 | |
2.7 2014/03/24 15:05:51 33.801 -118.109 9.7 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(ggmap) | |
library(plyr) | |
library(grid) | |
library(gridExtra) | |
# read in cleaned up data | |
dat <- read.table("quakes.dat", header=TRUE, stringsAsFactors=FALSE) | |
# map decimal magnitudes into an integer range | |
dat$m <- cut(dat$MAG, c(0:10)) | |
# convert to dates | |
dat$DATE <- as.Date(dat$DATE) | |
# so we can re-order the data frame | |
dat <- dat[order(dat$DATE),] | |
# not 100% necessary, but get just the numeric portion of the cut factor | |
dat$Magnitude <- factor(as.numeric(dat$m)) | |
# sum up by date for the barplot | |
dat.sum <- count(dat, .(DATE, Magnitude)) | |
# start the ggmap() bit | |
# It's super-handy that it understands things like "Los Angeles" #spoffy | |
# I like the 'toner' version. Would also use a stamen map but I can't get | |
# to it consistently from behind a proxy server | |
la <- get_map(location="Los Angeles", zoom=10, color="bw", maptype="toner") | |
# get base map layer | |
gg <- ggmap(la) | |
# add points. Note that the plot will produce warnings for all points not in the | |
# lat/lon range of the base map layer. Also note that i'm encoding magnitude by | |
# size and color and using alpha for depth. because of the way the data is sorted | |
# the most recent quakes in the set should be on top | |
gg <- gg + geom_point(data=dat, | |
mapping=aes(x=LON, y=LAT, | |
size=MAG, fill=m, alpha=DEPTH), shape=21, color="black") | |
# this takes the magnitude domain and maps it to a better range of values (IMO) | |
gg <- gg + scale_size_continuous(range=c(1,15)) | |
# this bit makes the right size color ramp. i like the reversed view better for this map | |
gg <- gg + scale_fill_manual(values=rev(terrain.colors(length(levels(dat$Magnitude))))) | |
gg <- gg + ggtitle("Recent Earthquakes in CA & NV") | |
# no need for a legend as the bars are pretty much the legend | |
gg <- gg + theme(legend.position="none") | |
# now for the bars. we work with the summarized data frame | |
gg.1 <- ggplot(dat.sum, aes(x=DATE, y=freq, group=Magnitude)) | |
# normally, i dislike stacked bar charts, but this is one time i think they work well | |
gg.1 <- gg.1 + geom_bar(aes(fill=Magnitude), position="stack", stat="identity") | |
# fancy, schmanzy color mapping again | |
gg.1 <- gg.1 + scale_fill_manual(values=rev(terrain.colors(length(levels(dat$Magnitude))))) | |
# show the data source! | |
gg.1 <- gg.1 + labs(x="Data from: http://www.data.scec.org/recent/recenteqs/Maps/Los_Angeles.html", y="Quake Count") | |
gg.1 <- gg.1 + theme_bw() | |
# use grid.arrange to make the sizes work well | |
grid.arrange(gg, gg.1, nrow=2, ncol=1, heights=c(3,1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment