在rstudio中从shapefile打印图层时遇到困难

在rstudio中从shapefile打印图层时遇到困难,r,gis,shapefile,R,Gis,Shapefile,我正在尝试从一个简单的形状文件加载并绘制一个图层。这是美国的国家边界。我可以很好地加载它: > library("sp","rgdal") > shape = readOGR("/home/username/data/share/mapnik/world_boundaries/states_EPSG4326.shp", layer="states_EPSG4326") OGR data source with driver: ESRI Shapefile Sou

我正在尝试从一个简单的形状文件加载并绘制一个图层。这是美国的国家边界。我可以很好地加载它:

> library("sp","rgdal")

> shape = readOGR("/home/username/data/share/mapnik/world_boundaries/states_EPSG4326.shp", layer="states_EPSG4326")

    OGR data source with driver: ESRI Shapefile 
    Source: "/home/username/data/share/mapnik/world_boundaries/states_EPSG4326.shp", layer:       "states_EPSG4326"
    with 2895 features and 9 fields
    Feature type: wkbPolygon with 2 dimensions
但它未能策划:

> plot(shape)

There were 50 or more warnings (use warnings() to see the first 50)
There were 50 or more warnings (use warnings() to see the first 50)
> warnings()
Warning messages:
1: Path drawing not available for this device
2: Path drawing not available for this device
3: Path drawing not available for this device
...
我错过了什么?绘图窗口中未显示任何内容。此形状文件中只有一个图层。我可以在qgis中绘制它,我正试图为它找到一个替代方案。R似乎是一个受欢迎的选择,但到目前为止我运气不太好。我在谷歌上搜索了这个警告,但没有找到任何有用的东西

编辑: 我尝试过的每个形状文件都会收到相同的响应。下面是我验证过的一个shapefile,其响应方式相同:

以下是sessionInfo()的输出:

这也是gentoo系统,在dev lang/R上启用了以下使用标志:

  • X icu java jpeg nls openmp png读线tiff
未启用以下使用标志(未编译功能):

  • -bash完成-cairo-doc-lapack-minimal-perl-profile-static libs-tk”
我唯一怀疑的两个是cairo和tk,他们是否需要策划

我用相似的结果从终端运行R,但结果不完全相同:

> shape = readOGR("/home/username/Downloads/state/statep010.shp", layer="statep010")
OGR data source with driver: ESRI Shapefile 
Source: "/home/username/Downloads/state/statep010.shp", layer: "statep010"
with 62 features and 9 fields
Feature type: wkbPolygon with 2 dimensions
> plot(shape)
There were 50 or more warnings (use warnings() to see the first 50)
> warnings()
Warning messages:
1: In polypath(x = mcrds[, 1], y = mcrds[, 2], border = border,  ... :
  Path drawing not available for this device
2: In polypath(x = mcrds[, 1], y = mcrds[, 2], border = border,  ... :
  Path drawing not available for this device
3: In polypath(x = mcrds[, 1], y = mcrds[, 2], border = border,  ... :
  Path drawing not available for this device
...

使用Roger Bivand在中描述的
plot(shape,usePolypath=FALSE)

如果您只对绘制管理边界感兴趣,您不能只使用一些R包提供的数据源吗

地图
提供全球行政区域。您也可以检索国家边界。请参见ggplot使用的示例

dismo
提供来自的数据。您可以按国家和级别检索数据

library(maps)
library(raster)

admlim <-getData('GADM', country='USA', level=1)
proj4string(admlim) <- CRS('+init=epsg:4326')
# plot(admlim) # plain plot
# dataframe for ggplot()
# This will take a long, long time for USA level 1 data from GADM
t.adm <- fortify(admlim)
ggplot(aes(long, lat, group = group), data = t.adm,
  colour = 'grey20', fill = NA) +
  geom_path() +
  scale_y_continuous(breaks=(-2:2) * 30) +
  scale_x_continuous(breaks=(-4:4) * 45) +
  coord_map('ortho', orientation=c(41, -74, 0))
库(地图)
图书馆(光栅)

admlim我也遇到了同样的问题,在安装libcairo2-dev和libpango1.0-dev之后,我可以通过再次编译R来解决这个问题

关于debian:

sudo apt install libcairo2-dev
sudo apt install libpango1.0-dev
我确信libpango1.0-dev以前就不存在了

./configure --prefix=/.../.../R --with-cairo
make && make install
这就解决了问题


希望能有所帮助。

如果无法重现您的问题,很难说。您能以某种方式共享数据吗,例如通过Dropbox或文件共享服务?@SlowLearner,谢谢,我编辑了原始问题,其中包含指向形状文件的链接,无法在此处绘制。@Nomadice我在windows下测试了您的形状文件。它可以工作,我有e map.@nomadicME在Unix下也能工作!在我的系统(Ubuntu 64位)上也能工作。你试过从命令行运行吗?如你提供的链接所述,如果我发出以下命令:
set\u Polypath(FALSE)
,那么我就可以继续使用
plot(shape)
,这更方便。
./configure --prefix=/.../.../R --with-cairo
make && make install