使用plot()绘制shapefile时如何设置线宽和颜色

Cpt*_*emo 10 maps plot r shapefile

我有一个简单的shapefile我想用一般情节绘图()(我注意到ggplot在绘制地图时非常慢).

我可以用代码正确地绘制形状

library(maptools)    
map_shp <- readShapePoly(map_filepath)
map <- fortify(map_shp)
plot(map)
Run Code Online (Sandbox Code Playgroud)

但是我怎样才能定义线条的颜色和宽度?

Jos*_*ien 20

如果您没有开始使用ggplot2来处理所有事情,您可以回避fortify()并使用sp包的完善工具来绘制类的对象SpatialPolygons*:

library(rgdal) # For readOGR(), generally preferable to readShapePoly() IMHO
library(spdep) # For the "columbus.shp" file that ships with the package

map <- readOGR(dsn = system.file("etc/shapes", package="spdep"), 
               layer = "columbus")
plot(map, border="red", lwd=3)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • @CptNemo - 我可能不是评论的合适人选,因为我不使用**ggplot2**.我确实使用R进行映射和空间分析,并且可以告诉你**sp**,**raster**,**rasterVis**包对base和**lattice**图形有很好的支持.此外,我听到了其他人对**ggplot2**的抱怨,然后建议他们使用**格子**或基本图形. (3认同)