Specifying plot order with ggsubplot

前端 未结 2 1761
滥情空心
滥情空心 2021-01-03 16:27

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

2条回答
  •  耶瑟儿~
    2021-01-03 16:40

    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)
    

提交回复
热议问题