10

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?

CptNemo
  • 6,455
  • 16
  • 58
  • 107

1 Answers1

21

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

Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455
  • Do you suggest to use ggplot2 also for rendering maps? I noticed it is very slow. – CptNemo Sep 25 '13 at 01:48
  • 3
    @CptNemo -- I might not be the right person to comment, since I don't use **ggplot2**. I do use R for mapping and spatial analyses, and can tell you that the **sp**, **raster**, **rasterVis** packages have good support for base and **lattice** graphics. Also, I've heard your same complaint about **ggplot2** from others, followed by the recommendation that they use **lattice** or base graphics instead. – Josh O'Brien Sep 25 '13 at 16:09