Avoiding hoizontal lines and crazy shapes when plotting maps in ggplot2

社会主义新天地 提交于 2019-12-03 13:07:36

The other solution is to restrict the view, rather than remove point from the render:

library(ggplot2)
library(maptools)
library(mapproj)

# Maptools dataset
data(wrld_simpl)
world <- fortify(wrld_simpl)

# Same plot, but restrict the view instead of removing points
# allowing the complete render to happen
ggplot(world, mapping = aes(x = long, y = lat, group = group)) +
  geom_polygon(fill = "black", colour = "black") +
  coord_cartesian(xlim = c(-125, -30), ylim = c(-60, 35))

You should delete the data outside the plot region. So, use scale_x/y_continuous to set the limits instead of coord_map

ggplot(data = df0, mapping = aes(x = long, y = lat, group = group)) +
  scale_x_continuous(limits = c(-125, -30)) +
  scale_y_continuous(limits = c(-60, 35)) +
  geom_polygon(fill = "black", colour = "black")

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