我是 R 新手,并且正在按照此处找到的 ggplot2 包的以下教程进行操作。但是,每当我尝试加载基本 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 的修复。