mapping by ggplot2 geom_polygon goes crazy after merging data

房东的猫 提交于 2019-12-06 08:36:22

Use geom_map() (which requires a slight tweak of your shapefile for some reason) so you don't have to do the merge/left join.

Also, you merged a great deal of different factors, not sure which ones you want to plot.

Finally, it's unlikely the coastal areas need that fine level of detail. rgeos::gSimplify() will definitely speed things up and you're already distorting areas, so a smaller bit of additional distortion won't impact the results.

library(ggplot2)
library(tidyverse)

shape_map <- tbl_df(fortify(shape, region="Name"))
colnames(shape_map) <- c("long", "lat", "order", "hole", "piece", "region", "group")

prop.test <- proptest.result[which(proptest.result$variable=="Upward N"),]

ggplot() +
  geom_map(data=shape_map, map=shape_map, aes(long, lat, map_id=region)) +
  geom_map(
    data=filter(prop.test, season=="DJF"),
    map=shape_map, aes(fill=prop.mega, map_id=megaregion)
  )

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!