【问题标题】:Map region with sf package in R在 R 中使用 sf 包映射区域
【发布时间】:2018-11-18 09:40:58
【问题描述】:

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

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

从这一点来看,我很困惑我必须做什么才能得到我想要的结果。

感谢您的帮助。

【问题讨论】:

  • 如果你使用sf,使用read_sf会更容易
  • 您想要使用 sf 的解决方案,还是说您不想使用 sf?
  • @sebdalgarno 我想要一个 sf 的解决方案,因为我从未使用过它。
  • @geo_dd 该解决方案对您有用吗?

标签: r dictionary grid area sf


【解决方案1】:

有了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))

【讨论】:

  • 很遗憾,您的解决方案对我不起作用,因为我找不到 geom_sf。
  • 你需要从 GitHub 安装 ggplot2 的开发版本。请查看我更新的解决方案。
  • @sebdalgano,还是同样的问题。我会做一些挖掘,因为如果这对你有用,那就意味着代码是好的。我在 ubuntu 上,可能需要安装更多软件包。我会告诉你的。
  • 你重新安装ggp​​lot2后是否重启了R?已经回答了许多其他 SO 问题...stackoverflow.com/questions/46817128/…stackoverflow.com/questions/46185226/…
猜你喜欢
  • 2011-03-12
  • 1970-01-01
  • 1970-01-01
  • 2021-09-22
  • 2018-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多