【问题标题】:r: readOGR & st_read giving two different plots?r: readOGR & st_read 给出两个不同的图?
【发布时间】:2018-12-26 17:39:18
【问题描述】:

我正在尝试使用 sf 和 ggplot 包制作地图。但是,当我运行 st_read() 命令读取我的 shapefile 并进行绘制时,它并没有给我想要的东西。但是当我用 readOGR 读入并绘制它时,它就是。我想使用 sf 包,因为对我来说它似乎更容易.. 为什么会这样做?任何帮助将不胜感激!谢谢!

使用的代码:

NJ_Map_Road<-st_read(dsn="V:/lum/WM&S/BEAR (Bureau of Environmental Analysis and Restoration)/Envpln/Hourly Employees/KevinZolea/Rwork/2014IR/Maps/shapefiles",layer="2014_NJ_Integrated_Report_AU")
NJ_OGR<-readOGR(dsn="V:/lum/WM&S/BEAR (Bureau of Environmental Analysis and Restoration)/Envpln/Hourly Employees/KevinZolea/Rwork/2014IR/Maps/shapefiles",layer="2014_NJ_Integrated_Report_AU")

数据结构:

NJ_Map_Road

Classes ‘sf’ and 'data.frame':  958 obs. of  14 variables:
 $ OBJECTID  : num  1 2 3 4 5 6 7 8 9 10 ...
 $ AU_NUM    : Factor w/ 958 levels "02020007000010-01",..: 6 81 372 59 91 385 380 127 414 417 ...
 $ AU_NAME   : Factor w/ 958 levels "Absecon Creek (AC Reserviors) (gage to SB)",..: 318 660 840 791 920 576 955 618 927 418 ...
 $ HUC14TXT  : Factor w/ 958 levels "BarnegatBay01",..: 23 98 389 76 108 402 397 144 431 434 ...
 $ WMA       : Factor w/ 20 levels "01","02","03",..: 2 3 1 6 3 1 1 5 1 1 ...
 $ AQUATICLIF: Factor w/ 4 levels "Sublist 2","Sublist 3",..: 4 4 1 2 4 4 4 4 2 1 ...
 $ AQUATICL_1: Factor w/ 5 levels "NA","Sublist 2",..: 3 5 5 5 5 3 5 1 5 5 ...
 $ FISHCONSUM: Factor w/ 4 levels "Sublist 2","Sublist 3",..: 2 2 2 2 2 4 3 2 2 2 ...
 $ RECREATION: Factor w/ 4 levels "Sublist 2","Sublist 3",..: 2 2 2 2 3 2 2 3 2 2 ...
 $ SHELLFISH : Factor w/ 5 levels "NA","Sublist 2",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ PUBLICWATE: Factor w/ 5 levels "NA","Sublist 2",..: 2 5 3 2 2 2 3 5 3 3 ...
 $ SHAPE_Leng: num  57104 140114 100002 78413 143794 ...
 $ SHAPE_Area: num  1.53e+08 5.12e+08 3.81e+08 2.39e+08 3.03e+08 ...
 $ geometry  :sfc_MULTIPOLYGON of length 958; first list element: List of 1

NJ_OGR

Formal class 'SpatialPolygonsDataFrame' [package "sp"] with 5 slots
  ..@ data       :'data.frame': 958 obs. of  13 variables:
  ..@ polygons   :List of 958
  ..@ plotOrder  : int [1:958] 950 844 853 421 687 329 334 721 251 321 ...
  ..@ bbox       : num [1:2, 1:2] 190378 10574 659480 919549
  .. ..- attr(*, "dimnames")=List of 2
  ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot

我用 readOGR 得到的情节:

我用 st_read 得到的情节

我很困惑!!!!

【问题讨论】:

    标签: r dictionary ggplot2 shapefile sf


    【解决方案1】:

    你读过plotting vignettesf 吗?默认情况下,plot()sf 对象上调用会绘制该对象的所有属性的颜色图,最大值约为 10。如果您只需要轮廓,即只需要几何图形,则需要绘制几何图形部分sf 对象。试试plot(st_geometry(NJ_Map_Road))plot(NJ_Map_Road$geometry),应该都可以。

    我建议你也看看first vignette,它描述了sfsf(简单特征)、sfc(简单特征几何列)和sfg(简单特征几何)类型之间的关系。包。

    【讨论】:

    • 我没有读过。谢谢你链接。那行得通。这与ggplot的概念相同吗?因为当我尝试使用 ggplot 时,它给了我完全不同的东西。
    • 不,sf 为遵循这些规则的sf 对象实现plot() 的方法。 ggplot2 实现了 geom_sf,它做了一些不同的事情,更符合 ggplot2 的其余部分,即除非使用 aes 明确映射,否则您不会绘制属性。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-14
    • 1970-01-01
    • 2022-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多