Convert SpatialPolygonsDataFrame or SpatialPixelsDataFrame object to data frame.
SpatialPolygonsDataFrame_to_df(sp_polys, vars = names(sp_polys))
Arguments
sp_polys: object of class SpatialPolygonsDataFrame or SpatialPixelsDataFrame
vars: variables to put into data frame (by default all of them)
Details
This function is mainly used for plotting SpatialPolygonsDataFrame objects with ggplot rather than spplot. The coordinates of each polygon are extracted and concatenated into one long data frame. The attributes of each polygon are then attached to this data frame as variables that vary by polygon id (the rownames of the object).