2016-06-24 1 views
1

map_dataでgeom_mapを使用しましたが、HIとAKは含まれていません。私は米国国勢調査のgeom_polygonとstate.centerで米国国勢調査の地理的境界データを使用しましたが、一致しません。私はstackoverflowの関連記事を読んだが、私が実際に私の質問に答えていない読んだ。助言がありますか?ggplot2を使用して、状態の略語を中心にしたHIとAKで米国の州地図を描くにはどうすればよいですか?

答えて

2
library(choroplethr) 
library(ggplot2) 
library(devtools) 
install_github('arilamstein/[email protected]') 
library(choroplethrZip) 

data(df_zip_demographics) 
df_zip_demographics$value = df_zip_demographics$percent_asian 

zip_map = ZipChoropleth$new(df_zip_demographics) 
zip_map$ggplot_polygon = geom_polygon(aes(fill = value), 
             color = NA) 
zip_map$set_zoom_zip(state_zoom = NULL, 
        county_zoom = NULL, 
        msa_zoom = NULL, 
        zip_zoom = NULL) 
zip_map$title = "50 State Map for StackOverflow" 
zip_map$legend = "Asians" 
zip_map$set_num_colors(4) 
choro = zip_map$render() 
choro 

data(df_pop_state) 
outline = StateChoropleth$new(df_pop_state) 
outline = outline$render_state_outline(tolower(state.name)) 

choro_with_outline = choro + outline 
choro_with_outline 

また、ここでは状態のラベルを追加するコードです:https://github.com/arilamstein/choroplethr/blob/master/R/state.R#L33

50 states

2

あなたはのいくつかを移動する必要がありますので、あなたは再考えるあなたの戦略にビットをお勧めしますが、読みやすくするための状態ラベル。 Prbly shldは、あなたが動かすもののために状態からラベルに線を引きます。

library(ggplot2) 
library(ggalt)  # coord_proj 
library(albersusa) # devtools::install_github("hrbrmstr/albersusa") 
library(ggthemes) # theme_map 
library(rgeos)  # centroids 
library(dplyr) 

# composite map with AK & HI 
usa_map <- usa_composite() 

# calculate the centroids for each state 
gCentroid(usa_map, byid=TRUE) %>% 
    as.data.frame() %>% 
    mutate([email protected]$iso_3166_2) -> centroids 

# make it usable in ggplot2 
usa_map <- fortify(usa_map) 

gg <- ggplot() 
gg <- gg + geom_map(data=usa_map, map=usa_map, 
        aes(long, lat, map_id=id), 
        color="#2b2b2b", size=0.1, fill=NA) 
gg <- gg + geom_text(data=centroids, aes(x, y, label=state), size=2) 
gg <- gg + coord_proj(us_laea_proj) 
gg <- gg + theme_map() 
gg 

enter image description here

+0

これは素晴らしい作品。 HIをAKの左側に移動する方法はありますか? – tnabdb

+0

心配しないで、ただ翻訳を使用します。 – tnabdb

関連する問題