在R中使用sf包映射区域

时间:2018-06-08 10:36:49

标签: r dictionary grid area sf

我尝试了几天找到一种方法来处理R中的sf包,但没有成功。我想绘制我的区域与this example中的示例2类似,但没有任何要点。我将我的区域加载为SpatialpolygonsDataFrame,然后我使用fortify来获得lat和long,如下所示:

area<-readOGR(dsn="/home/ubuntu/..",layer="area")
f_area<-fortify(area)
head(f_area) 

long      lat order  hole piece id group
1 116.1045 57.23717     1 FALSE     1  0   0.1
2 116.1551 57.21548     2 FALSE     1  0   0.1
3 116.2420 57.14505     3 FALSE     1  0   0.1
4 116.1706 57.12011     4 FALSE     1  0   0.1
5 116.1222 57.12006     5 FALSE     1  0   0.1
6 116.0756 57.09926     6 FALSE     1  0   0.1

从这一点来说,我很困惑我必须做些什么来获得我想要的结果。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

使用ggplot2 :: geom_sf,无需强化。

# install ggplot2 development version
install.packages('devtools')
devtools::install_github('tidyverse/ggplot2')

# load libraries
library(sf)
library(ggplot2)

# read in data (probably you need to change the path here to read your file)
area <- sf::st_read("/home/ubuntu/area.shp")

# ggplot
ggplot() + geom_sf(area)

# or you can simply use plot
plot(st_geometry(area))