我正在尝试使用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获得的剧情
我很困惑!!!!
答案 0 :(得分:1)
您是否读过sf
的{{3}}?默认情况下,在plot()
对象上调用的sf
会绘制该对象的所有属性的颜色图,最多约10个最大值。如果只需要轮廓,即仅几何形状,则需要绘制sf
对象的几何部分。尝试plot(st_geometry(NJ_Map_Road))
或plot(NJ_Map_Road$geometry)
,两者都应该起作用。
我建议您还查看plotting vignette,它描述sf
(简单特征),sfc
(简单特征几何列)和sfg
(简单特征)之间的关系sf
包中的类型。