ggplot/mapping US counties — problems with visualization shapes in R

前端 未结 6 2153
迷失自我
迷失自我 2020-12-13 16:14

So I have a data frame in R called obesity_map which basically gives me the state, county, and obesity rate per county. It looks more or less like this:

obesi         


        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 17:05

    I think all you needed to do was reorder the map.county variable like you had for the map.data variable previously.

    ....
    map.county <- merge(county.obesity, map.county, all=TRUE)
    
    ## reorder the map before plotting
    map.county <- map.county[order(map.data$county),] 
    
    ## plot
    ggplot(map.county, aes(x = long, y = lat, group=group, fill=as.factor(value))) + geom_polygon(colour = "white", size = 0.1)
    

提交回复
热议问题