shapefile使用的坐标系不是lat-lon。您应该在将其转换为数据帧之前对其进行转换 ggplot 。以下作品:
ggplot
shpfile <- spTransform(shpfile, "+init=epsg:4326") # transform coordinates tidydta2 <- tidy(shpfile, group=group) wisc <- get_map(location = c(lon= -89.75, lat=44.75), zoom=7) ggmap(wisc) + geom_polygon(aes(x=long, y=lat, group=group), data=tidydta2, color="dark red", alpha=.2, size=.2)
为了将来参考,请通过将数据框打印到带有可见x / y轴标签的控制台/绘图来检查坐标值。如果数字与背景地图的边界框的数字大不相同(例如7e + 05与47),则可能需要进行一些转换。例如。:
> head(tidydta) # coordinate values of dataframe created from original shapefile # A tibble: 6 x 7 long lat order hole piece group id <dbl> <dbl> <int> <lgl> <chr> <chr> <chr> 1 699813. 246227. 1 FALSE 1 0.1 0 2 699794. 246082. 2 FALSE 1 0.1 0 3 699790. 246007. 3 FALSE 1 0.1 0 4 699776. 246001. 4 FALSE 1 0.1 0 5 699764. 245943. 5 FALSE 1 0.1 0 6 699760. 245939. 6 FALSE 1 0.1 0 > head(tidydta2) # coordinate values of dataframe created from transformed shapefile # A tibble: 6 x 7 long lat order hole piece group id <dbl> <dbl> <int> <lgl> <chr> <chr> <chr> 1 -87.8 42.7 1 FALSE 1 0.1 0 2 -87.8 42.7 2 FALSE 1 0.1 0 3 -87.8 42.7 3 FALSE 1 0.1 0 4 -87.8 42.7 4 FALSE 1 0.1 0 5 -87.8 42.7 5 FALSE 1 0.1 0 6 -87.8 42.7 6 FALSE 1 0.1 0 > attr(wisc, "bb") # bounding box of background map # A tibble: 1 x 4 ll.lat ll.lon ur.lat ur.lon <dbl> <dbl> <dbl> <dbl> 1 42.2 -93.3 47.2 -86.2 # look at the axis values; don't use theme_void until you've checked them cowplot::plot_grid( ggplot() + geom_polygon(aes(x=long, y=lat, group=group), data=tidydta, color="dark red", alpha=.2, size=.2), ggplot() + geom_polygon(aes(x=long, y=lat, group=group), data=tidydta2, color="dark red", alpha=.2, size=.2), labels = c("Original", "Transformed") )