Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

sp2df

Transforms a shapefile into a dataframe


Description

This function takes in a shapefile (formal class of SpatialPolygonsDataFrame) and transforms it into a dataframe

Usage

sp2df(map, ...)

Arguments

map

A map object of class SpatialPolygonsDataFrame

...

Other arguments, currently ignored

Value

A dataframe, in which the first 7 columns hold geographical information (ex: long and lat)

Examples

## Not run:  
if(require(maptools)) {
  data(wrld_simpl)
  worldmap <- sp2df(wrld_simpl)
}

if ( require(ggplot2) && require(maptools) ) { 
  data(wrld_simpl)
  World <- sp2df(wrld_simpl)
  World2 <- merge(World, Countries, by.x="NAME", by.y="maptools", all.y=FALSE)
  Mdata <- merge(Alcohol, World2, by.x="country", by.y="gapminder", all.y=FALSE) 
  Mdata <- Mdata[order(Mdata$order),]
  qplot( x=long, y=lat, fill=ntiles(alcohol,5), 
         data=subset(Mdata, year==2008), group = group, 
                     geom="polygon")
}

## End(Not run)

mosaic

Project MOSAIC Statistics and Mathematics Teaching Utilities

v1.8.3
GPL (>= 2)
Authors
Randall Pruim [aut, cre], Daniel T. Kaplan [aut], Nicholas J. Horton [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.