I\'m adding bar-plots to maps using ggplot and ggsubplot, but cannot figure out how to specify which to plot first. I\'d like to plot the northerly ones first so they sit b
Is this what you had in mind?
You need to order d
by latitude, as you pointed out, and also use group=lat
in the call to geom_subplot(...)
.
set.seed(1)
d = ddply(world_map,.(region),summarize,long=mean(long),lat=mean(lat))
d = d[sample(1:nrow(d), 50),]
d = rbind(d,d)
d$cat = rep(c('A','B'), each=nrow(d)/2)
d$value = sample(1:10, nrow(d), rep=T)
d <- d[order(d$lat),]
head(d)
p + geom_subplot(data=d, aes(long, lat, group=lat,
subplot = geom_bar(aes(cat, value, fill=cat),
col='black', alpha=0.9, stat="identity")), width = 30, height=30)
The underlying map was pretty much of a mess in the resulting figure, but this pre-ordering seemed to bring the high latitude items to the front:
world_map = world_map[order(world_map$lat),]
It wasn't clear whether you wanted the negative latitudes to be plotted under the latitudes nearer the Equator, so you also have the option of using abs(world_map$lat) as the order.