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)