我正在尝试使用ggplot将热图绘制到地图上(效果很好)但是如果我限制轴,我的geom_polygon覆盖会以错误的方式连接点.
ggplot(2017.fixes, aes(x=Long, y=Lat) ) +
stat_density_2d(aes(fill = ..density..), geom = "raster", contour=F)+
scale_fill_distiller(palette="PuBu", direction=1) +
geom_polygon (data=map.df,aes(x=long, y=lat,group=group), color="grey50", fill="grey", na.rm=T) +
#xlim(-156.95, -156.4)+
#ylim(20.55, 21.05 )+
coord_fixed()
Run Code Online (Sandbox Code Playgroud)
产生这个:
但如果我取消注释xlim和ylim我得到这个:
它显然正确地切断了左岛,但不是其他两个,我不知道为什么.
代替
xlim(-156.95, -156.4) +
ylim(20.55, 21.05) +
coord_fixed()
Run Code Online (Sandbox Code Playgroud)
使用:
coord_cartesian(xlim = c(-156.95, -156.4), ylim = c(20.55, 21.05)) +
Run Code Online (Sandbox Code Playgroud)
这会在不删除数据的情况下限制轴.
http://ggplot2.tidyverse.org/reference/coord_cartesian.html
还可以尝试coord_map绘制地图.
https://ggplot2.tidyverse.org/reference/coord_map.html
| 归档时间: |
|
| 查看次数: |
514 次 |
| 最近记录: |