I use to be able to run this script without any problem, but now the fortify {ggplot2} command gives me an error message. Any hint of what might be the problem would be great! I used the fortify command to be able to geom_map the shapefile using ggplot2.
Below is my script and link for downloading the data.
#######################################################
#######################################################
rm(list = ls(all = TRUE))#clear workspace
getwd()
#upload packages
library(maps)
library(mapdata)
library(gridExtra)
library(rgdal)
library(rgeos)
library(ggplot2)
library(sp)
library(maptools)
gpclibPermit()
#setwd(".../FAO") FAO data are major fishing area divisions
> FAO<- readOGR(dsn="fao", layer="World_Fao_Zones")
OGR data source with driver: ESRI Shapefile
Source: "fao", layer: "World_Fao_Zones"
with 19 features and 1 fields
Feature type: wkbPolygon with 2 dimensions
> names(FAO);dim(FAO)
[1] "zone"
[1] 19 1
> str(FAO,max.level=2)
Formal class 'SpatialPolygonsDataFrame' [package "sp"] with 5 slots
..@ data :'data.frame': 19 obs. of 1 variable:
..@ polygons :List of 19
..@ plotOrder : int [1:19] 18 2 17 4 12 3 13 11 5 6 ...
..@ bbox : num [1:2, 1:2] -180 -85.5 180 90
.. ..- attr(*, "dimnames")=List of 2
..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
> plot(FAO)
FAO@data$id = rownames(FAO@data)
FAO.df <- as.data.frame(FAO)# convert shapefile to dataframe to merge later
> FAO_fort <- fortify(FAO, region="id")# fortify to plot with ggplot2
Error in function (classes, fdef, mtable) :
unable to find an inherited method for function "proj4string", for signature "NULL"
Here's a link to download the data FAO data. Thank you!