Hello all, I'm working on a map. I'd like to extract centroids of the counties below in order to plot them as points. How can I do this?
Many thanks, Andy
~~~~
library(ggplot2)
library(maps)
all_states <- map_data("county")
states <- subset(all_states, region %in% c("iowa", "illinois", "indiana",
"michigan", "minnesota","ohio",
"wisconsin"))
p <- ggplot()
p <- p + geom_polygon( data=states, aes(x=long, y=lat, group = group),
color="grey10", fill="white" )
p <- p + theme(aspect.ratio=1)
p
extracting centroids from map data
2 messages · Andy Bunn, Bede-Fazekas Ákos
Hello Andy, you'll need these: library(rgeos) centroids <- gCentroid(states, byid=TRUE, id = NULL) after you convert your data.frame to SpatialPolygons or SpatialPolygonsDataFrame (package sp). HTH, ?kos 2016.05.20. 5:41 keltez?ssel, Andy Bunn ?rta:
Hello all, I'm working on a map. I'd like to extract centroids of the counties below in order to plot them as points. How can I do this?
Many thanks, Andy
~~~~
library(ggplot2)
library(maps)
all_states <- map_data("county")
states <- subset(all_states, region %in% c("iowa", "illinois", "indiana",
"michigan", "minnesota","ohio",
"wisconsin"))
p <- ggplot()
p <- p + geom_polygon( data=states, aes(x=long, y=lat, group = group),
color="grey10", fill="white" )
p <- p + theme(aspect.ratio=1)
p
[[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo