强化adm0 SpatialPolygonsDataFrame上的行为 [英] fortify behaving strangely on adm0 SpatialPolygonsDataFrame

查看:187
本文介绍了强化adm0 SpatialPolygonsDataFrame上的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在ggplot中做一些情节,与R内置的绘图功能相比,我更愿意使用这些情节。然而,在我使用的文件之一(包含肯尼亚地图的SpatialPolygonsDataFrame)中,当我尝试调用SPDF的fortify以将其转换为data.frame时,绘制结果会在特别锯齿状的区域产生奇怪的行为的边界,而阴谋管理工作正常。任何人有任何想法是什么?

 库(sp)
库(ggplot2)

riso< - KEN
查询< - paste0(http://biogeo.ucdavis.edu/data/gadm2/R/,riso,_adm0.RData)
destination < - myfile.RData
download.file(query,destination)
load(destination)
plot(gadm)

map< - fortify(gadm)
g < - ggplot()+ geom_path(data = map,aes(x = long,y = lat))
g
pre>




<只需将 group = group 添加到 aes()映射。希望我能解释为什么这会起作用。

  g < -  ggplot()+ geom_path(data = map,aes(x = long,y = lat,group =组))
g


I'm trying to do some plots in ggplot, which I'm much more comfortable working with than R's built in plotting function. However, with one of the file's I'm using (a SpatialPolygonsDataFrame containing a map of Kenya), when I try to call fortify on the SPDF to convert it to a data.frame, plotting the result yields odd behavior in a particularly jagged region of the border, while plot manages to work fine. Anyone have any ideas as to what's going on?

library(sp)
library(ggplot2)

riso <- "KEN"
query <- paste0("http://biogeo.ucdavis.edu/data/gadm2/R/", riso, "_adm0.RData")
destination <- "myfile.RData"
download.file(query, destination)
load(destination)
plot(gadm)

map <- fortify(gadm)
g <- ggplot() + geom_path(data = map, aes(x = long, y = lat))
g

解决方案

Just add group = group to the aes() mappings. Wish I could explain why this works.

g <- ggplot() + geom_path(data = map, aes(x = long, y = lat, group = group))
g

这篇关于强化adm0 SpatialPolygonsDataFrame上的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆