使用R

时间:2015-11-15 09:03:44

标签: r

我试图用R

绘制多边形
ggplot()+geom_polygon(d,aes(x=lon,y=lat))

with d是一个具有5个经度和纬度坐标的数据框文件。

但我有一个自相交的多边形。我怎样才能避免自相交

感谢

欢呼声

编辑 lon lat 1 113.8638 27.63341 2 113.8602 27.63427 3 113.8626 27.63278 4 113.8528 27.65023 5 113.8568 27.63601 6 113.8593 27.62754 7 117.6790 39.01934 8 117.6790 39.01934 9 117.6790 39.01934 这是坐标,我想根据这些数据点绘制一个非自相交的多边形

1 个答案:

答案 0 :(得分:2)

假设列表中的最后三个相同点是错误的,因此丢弃它们,可以使用其余数据绘制非重叠多边形,如下所示:

library(ggplot2)
library(grDevices)
df1 <- read.table(text="lon lat
     113.8638 27.63341
     113.8602 27.63427
     113.8626 27.63278
     113.8528 27.65023
     113.8568 27.63601
     113.8593 27.62754",header=T)
df2 <- df1[chull(df1),]
p <- ggplot() + geom_point(data=df1, aes(x=lon, y=lat))+
     geom_polygon(data=df2, aes(x=lon,y=lat, col=2, alpha=0.4) )+ 
     theme(legend.position="none")

enter image description here

如果您不想要凸多边形,事情会变得更加复杂。然后,您可能需要对数据框中的点序列进行重新排序,并且我不知道采用简单的编程方法来解决这个问题。

相关问题