Plotting bar graph on a map

52 views
Skip to first unread message

Hasan Diwan

unread,
Oct 31, 2017, 6:38:12 PM10/31/17
to ggplot2
I see a possible solution to what I want to do is geom_subplot, but that package seems to be abandoned. What I have is a CSV consisting of latitude, longitude, and magnitudes of earthquakes over the past 2 weeks and I'd like to plot it on a map. What I have so far follows:

require(maps)

require(ggplot2)

require(ggthemes)

quake.data <- read.csv('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.csv')

quake.data <- quake.data[quake.data[,15] == 'earthquake',] # earthquakes only, wtf are ice quakes anyway?

mapWorld <- borders("world", colour="gray50", fill="gray50") # create a layer of borders

ggplot() + mapWorld + geom_point(data = quake.data, aes(x=longitude, y=latitude, colour = mag, size=mag*10)) + ggtitle('Last week quakes visualised, size of the points is the magnitude', subtitle='Source: US Geological Survey') + theme_minimal()  + theme(axis.title.x = element_blank(), axis.title.y = element_blank()) + scale_colour_gradient2(guide = guide_legend(title = "Magnitude"))

Instead of geom_point, I'd rather use geom_bar to create a bar representing the earthquake's magnitude. A solution seems to be to use geom_subplot[1], but that package is archived and the package's most recent fork doesn't build on R 3.4.2[2]. Any other vectors perhaps sort this? Many thanks in advance... -- H

--

白铉

unread,
Nov 6, 2017, 7:22:14 AM11/6/17
to ggplot2


在 2017年11月1日星期三 UTC+8上午6:38:12,Hasan Diwan写道:

Ron Crump

unread,
Nov 6, 2017, 4:21:27 PM11/6/17
to 白铉, ggplot2
I would think you could do this via grobs.

But I might be wrong and don't have access to a PC at present to have a play.

You might get some hints at https://ikashnitsky.github.io/2017/align-six-maps/ although they are arranging plots on a page rather than on another plot, but I'd think the concept is similar.

What I'm not sure about is why you would use a bar plot to represent a single data point for each earthquake. Wouldn't geom_point with colour or size mapped to magnitude be more appropriate? And much simpler to implement.

Regards,
Ron.
Reply all
Reply to author
Forward
0 new messages