Cleaning up a map using geom_tile

前端 未结 1 1128
南旧
南旧 2021-01-15 23:33

Thanks to help from some users on this site, I was able to get a nice map plot for some data using geom_point. (Get boundaries to come through on states) However, now I\'m

相关标签:
1条回答
  • 2021-01-15 23:43

    geom_tile needs your x and y values to be sampled on an regular grid. It needs to be able to tile the surface in rectangles. So your data is irregularly sampled, it's not possible to divide up the raw data into a bunch of nice tiles.

    One option is to use the stat_summary2d layer to divide your data into boxes and calculate the average APPT for all points in that box. This will allow you to create regular tiles. For example

    ggplot() + 
      geom_polygon(data=subset(map_data("state"), region %in% regions), aes(x=long, y=lat, group=group)) +
      stat_summary2d(data=PRISM_1895_db, aes(x = longitude, y = latitude, z = APPT)) +
      geom_polygon(data=subset(map_data("state"), region %in% regions), aes(x=long, y=lat, group=group), color="white", fill=NA)
    

    which produces

    enter image description here

    you can look at other options to control this bin sizes if you like. But as you can see it's "smoothing" out the data by taking averages inside bins.

    0 讨论(0)
提交回复
热议问题