i need to project result of my clustering in a geographic cart which i downloaded as shapefile
the problem is i do have an error that i couldn't fix it
shape <-readOGR(dsn = "polygon.shp")
###converting shapefile to a data frame
#Plotting a Plain Map
shape@proj4string
shp_df <- fortify(shape)
proj4string(shape)
######transform geographical base of my shapefile
tx_ll <- spTransform(shape, CRS("+proj=longlat +ellps=WGS84 +datum=WGS84"))
#transformer en data frame
shp_df1 <- fortify(tx_ll)
shpMap <- ggplot(data = shp_df1, aes(x=long,y=lat)) +
geom_polygon(aes(group = group), fill="black") +
coord_equal(xlim = c(1.220, 1.225), ylim = c(47.22 , 47.25)) +
labs(x = "Longitude ",
y = "Latitude ",
title = "Map ",
subtitle = "Map - Based on the Lat Long in Shape Files")
shpMap
### after that i want to do the same cart but with the projected classes of k_means clustering
km <- kmeans(tablevariable[,1:5],5 , nstart=20)
classes<-as.data.frame(km$centers)
shpMap1 <- ggplot(data = shp_df1, aes(x=long,y=lat)) +
geom_polygon(aes(group = group), fill="grey80") +
geom_point( aes(x =x, y = y), data = classes) +
coord_equal(xlim = c(1.220, 1.224), ylim = c(47.22 , 47.25)) +
labs(x = "Longitude",
y = "Latitude ",
title = "Map ",
subtitle = "Map - Based on the Lat Long in Shape Files")
shpMap1
but it gives me that error
Error: Aesthetics must be either length 1 or the same as the data (35968): x, y
can someone explain to me i don't know where is the problem