plotting pie graphs on map in ggplot

后端 未结 5 1304
情话喂你
情话喂你 2020-11-28 04:12

This may be a wish list thing, not sure (i.e. maybe there would need to be the creation of geom_pie for this to occur). I saw a map today (LINK) with pie graph

5条回答
  •  隐瞒了意图╮
    2020-11-28 05:15

    This functionality should be in ggplot, I think it is coming to ggplot soonish, but it is currently available in base plots. I thought I would post this just for comparison's sake.

    load(url("http://dl.dropbox.com/u/61803503/nycounty.RData"))
    
    library(plotrix)
    e=10^-5
    myglyff=function(gi) {
    floating.pie(mean(gi$long),
                 mean(gi$lat),
                 x=c(gi[1,"white"]+e,
                     gi[1,"black"]+e,
                     gi[1,"hispanic"]+e,
                     gi[1,"asian"]+e,
                     gi[1,"other"]+e),
                  radius=.1) #insert size variable here
    }
    
    g1=ny[which(ny$group==1),]
    plot(g1$long,
         g1$lat,
         type='l',
         xlim=c(-80,-71.5),
         ylim=c(40.5,45.1))
    
    myglyff(g1)
    
    for(i in 2:62)
      {gi=ny[which(ny$group==i),]
        lines(gi$long,gi$lat)
        myglyff(gi)
      }
    

    Also, there may be (probably are) more elegant ways of doing this in the base graphics.

    It's a New York Pie!!

    As, you can see, there are quite a few problems with this that need to be solved. A fill color for the counties. The pie charts tend to be too small or overlap. The lat and long do not take a projection so sizes of counties are distorted.

    In any event, I am interested in what others can come up with.

提交回复
热议问题