我是R的新手,正在按照这里找到的ggplot2包教程进行学习:here。但是当我尝试加载基本的shapefile时,readShapePoly()函数会抛出错误。我使用了以下代码:
library("ggplot2")
library("gpclib")
library("maptools")
setwd("~/Documents/R Projects/Intro to ggplot2")
#Intro to ggplot 2 contains the .shp file and associated data
sport <- readShapePoly("london_sport.shp")
这让我感到:
Error in getinfo.shape(filen) : Error opening SHP file
我已经尝试省略文件扩展名。我也尝试下载其他的 .shp 文件,但这些文件也会出现相同的错误。我还尝试使用完整的文件路径调用 readShapePoly,但也不起作用。我正在使用 R Studio (mac OSX),但是在标准的 R 窗口中也遇到了相同的错误。我尝试了之前关闭的威胁“在Rstudio中打开SHP文件时出错”的建议,但没有成功。
编辑:问题出在缺少 .dbf 文件上。感谢 @Spacedman 的修复。
readOGR
函数吗? - Ari B. Friedmanlist.files()
并查看返回的内容。你的 shapefile 是否在其中,并以正确的名称命名?当尝试使用readShapePoly
读取时,绝对不要添加扩展名。 - Simon O'Hanlonlondon_sport.shx
和london_sport.dbf
文件吗?你需要这三个文件才能制作一个“Shapefile”。 - Spacedman