I'm trying to fill in counties of states with data to help with a project I'm working on. I found a wonderful answer here on how to add county names to the county map of New York. I was able to use it to help on a few states, but am striking out when I attempt to use the maps of Texas and Louisiana. For reference, this is what I'm typing:
library(ggplot2)
library(sp)
library(maps)
getLabelPoint <- function(county) {Polygon(county[c('long', 'lat')])@labpt}
df <- map_data('county', 'louisiana')
centroids <- by(df, df$subregion, getLabelPoint)
It's at that point R spits out "Error in Polygon(county[c("long", "lat")]) : ring not closed"
I honestly don't even know where to start to fix this, so any help or even an alternative method would be awesome.