Often we have data that has some geographical aspect to it (such as postal codes) but does not have sufficient geographic coordinate information to plot. In order to display such information on a map representation, we will need to embellish the basic data with enough geographic coordinate information to plot.
The sp package has several SpatialXXXDataFrame classes to represent geographic information along with additional descriptive data. This recipe shows you how we can create and plot such objects. In this recipe, we demonstrate how to get a map from the maps package and convert it to a SpatialPolygons object. We then add data from a normal data frame to create a SpatialPolygonsDataFrame object, which we then plot.