Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set line width and color when plotting a shapefile with plot()

I have a simple shapefile I want to plot with the general plot() (I noticed that ggplot is extremely slow in plotting maps).

I can correctly plot the shape with the code

library(maptools)    
map_shp <- readShapePoly(map_filepath)
map <- fortify(map_shp)
plot(map)

But how could I define the color and width of the lines?

like image 398
CptNemo Avatar asked Sep 24 '13 23:09

CptNemo


1 Answers

If you aren't set on using ggplot2 for everything, you can sidestep fortify() and just use the sp package's well-developed tools for plotting objects of class 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)

enter image description here

like image 143
Josh O'Brien Avatar answered Nov 10 '22 16:11

Josh O'Brien