Note that there are some explanatory texts on larger screens.

plurals
  1. POImprove centering county names ggplot & maps
    text
    copied!<p>Early I posted a question about plotting county names on a map using ggplot and maps found <a href="https://stackoverflow.com/questions/9441436/ggplot-centered-names-on-a-map">HERE</a>. My first approach was to take the means of all the lat and long coordinates per county as seen here: <img src="https://i.stack.imgur.com/KsVzJ.png" alt="enter image description here"></p> <p>Thankfully Andrie had 2 suggestions to improve the centering using a center of ranges and then the coord_map() {which appears to keep the aspect ratio correct}. This imporved the centering a great deal as seen here: <img src="https://i.stack.imgur.com/KzoWr.png" alt="enter image description here"></p> <p>I think this looks better but still has some difficulties with overlap problems. I am hoping to further improve the centering (In that same thread Justin suggested a kmeans approach). I am ok with rotating text if necessary but am hoping for names that are centered and rotated if necessary (they extend beyond the county borders) to best display the county names on the map.</p> <p>Any ideas?</p> <pre><code>library(ggplot2); library(maps) county_df &lt;- map_data('county') #mappings of counties by state ny &lt;- subset(county_df, region=="new york") #subset just for NYS ny$county &lt;- ny$subregion p &lt;- ggplot(ny, aes(long, lat, group=group)) + geom_polygon(colour='black', fill=NA) #my first approach to centering cnames &lt;- aggregate(cbind(long, lat) ~ subregion, data=ny, FUN=mean) ggplot(ny, aes(long, lat)) + geom_polygon(aes(group=group), colour='black', fill=NA) + geom_text(data=cnames, aes(long, lat, label = subregion), size=3) #Andrie's much improved approach to centering cnames &lt;- aggregate(cbind(long, lat) ~ subregion, data=ny, FUN=function(x)mean(range(x))) ggplot(ny, aes(long, lat)) + geom_polygon(aes(group=group), colour='black', fill=NA) + geom_text(data=cnames, aes(long, lat, label = subregion), size=3) + coord_map() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload