I downloaded three different shapefiles of the city chicago. Now i wanted to combine them and plot them together. Only the ward-offices do not plot. '''Error: data
must be a data frame, or other object coercible by fortify()
, not an S4 object with class SpatialPointsDataFrame'''
The first two are polygons and the third is point oriented...
this is my code:
#setting directiories
chicagodir = 'Community Areas/'
chicagoshp = paste(chicagodir, "geo_export_b982773b-13a7-4b96-827d-d969f0695777.shp", sep = "")
chicagoread =readOGR(chicagoshp)
plot(chicagoread)
#Wardprecints facilities
wardprecinctsdir = 'WardPrecincts/'
wardprecinctsshp = paste(wardprecinctsdir, "WardPrecincts.shp", sep = "")
wardprecinctsshpread =readOGR(wardprecinctsshp)
plot(wardprecinctsshpread)
#Ward Offices - Map - Exportable
wardofficesdir = 'Ward Offices - Map - Exportable/'
wardofficesshp = paste(wardofficesdir, "geo_export_b47221aa-0cc1-45db-8a3c-3e6ba72dccf1.shp", sep = "")
wardofficesshpread = readOGR(wardofficesshp)
plot(wardofficesshpread)
chicago_transform <- spTransform(chicagoread, CRS("+proj=longlat +init=epsg:4326"))
wardpre_transform <-spTransform(wardprecinctsshpread, CRS("+proj=longlat +init=epsg:4326"))
wardoff_transform <-spTransform(wardofficesshpread, CRS("+proj=longlat +init=epsg:4326"))
combinedplot = ggplot() +
geom_path(data = chicago_transform, aes(x = long, y = lat, group = group)) +
coord_fixed() +
labs(title = "Plot of Chicago",
x = "long", y = "lat") +# Because we don't need x and y labels do we?
#add specific wardprecinctsshpread and wardoffices
geom_polygon(data=wardpre_transform, aes(x = long, y = lat, group = group, color="red")) +
geom_polygon(data=wardoff_transform, aes(x = long, y = lat, group = group, color="blue"))
combinedplot
'''
How do I resolve this, the plotting of points to the 2 polygons? thankyou in advance