문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top