StackOverflow から取得したコードを使用して、地図を陰影付けしたいだけでなく、郡名も表示したいと思います。
完璧な世界では、上位 5 つの郡名と下位 5 つの郡名のみを表示できるようにしたいと考えています。さらにひねりを加えて、上位の名前を赤で、下位の名前を黒で表示したいと考えています。
しかし、名前を取得したり、追加する他のオプションの例を見つけるのに十分な問題があります。
私はRが初めてで、これが正しい方法かどうかわかりません。
また、このように郡ごとに 3 つの変数 (収入、出生率、人口) を表示するために推奨されるビジュアライゼーションはありますか?
ありがとうございました
library(noncensus)
library(zipcode)
library(choroplethr)
library(ggplot2)
library(sp)
library(maps)
#this guy is pretty but needs county names
data(df_pop_county)
county_choropleth(df_pop_county,
title="US 2012 County Population Estimates",
legend="Population",
buckets=1,
zoom=c("new york"))
#this guy has county names
getLabelPoint <- # Returns a county-named list of label points
function(county) {Polygon(county[c('long', 'lat')])@labpt}
df <- map_data('county', 'new york') # NY region county data
centroids <- by(df, df$subregion, getLabelPoint) # Returns list
centroids <- do.call("rbind.data.frame", centroids) # Convert to Data Frame
names(centroids) <- c('long', 'lat') # Appropriate Header
map('county', 'new york')
text(centroids$long, centroids$lat, rownames(centroids), offset=0, cex=0.4)