2017-09-07 8 views
-1

ggmapの出力を拡大するのに助けてくれる人はいますか?ggmapの出力を拡大してグレーを取り除く

私は自分のマップを作るために、そこからモデルとして

ダミーデータthis siteを使用:

df <- data.frame(Current_zip_code=c(27103, 27540, 32669, 32765, 39180, 39553, 47403, 70118, 70119, 70364, 74114, 74133, 83703, 90045, 90263, 90278, 96706, 96707, 99506), total=c(1, 5, 7, 12, 15, 6, 17, 31, 12, 13, 6, 4, 4, 25, 41, 65, 33, 25, 22), latitude=c(36.066545, 35.643545, 29.640613, 28.656375, 32.292761, 30.400599, 39.121719, 29.952305, 29.974504, 29.626988, 36.126894, 36.04309, 43.668396, 33.960041, 34.035087, 33.871214, 21.338055, 21.345535, 61.224384), longitude=c(-80.30733, -78.83486, -82.59446, -81.21026, -90.87184, -88.65092, -86.57409, -90.12347, -90.08747, -90.72076, -95.94657, -95.88417, -116.25707, -118.3949, -118.70752, -118.37177, -158.02499, -158.08587, -149.77461)) 

library(fiftystater) 
data("usa") 
usa_center = as.numeric(geocode("United States")) 
USAMap = ggmap(get_googlemap(center=usa_center, scale=2, zoom=4), extent="normal") 

map_ex <- USAMap + 
    geom_point(aes(x=longitude, y=latitude), data=df, col="orange", alpha=0.4, size=df$total*.2) + 
    scale_size_continuous(range=range(df$total)) 

enter image description here

を出力マップは、中心から外れました。アラスカとハワイに友達を含めるためにそれを拡大する方法はありますか?私は灰色の背景と軸のタイトルが好きではありません。拡大してグレーと軸を取り除く方法はありますか?

Iこの

scale_x_continuous(limits = c(-95.5 , -95.3) , expand = c(0 , 0)) 

を追加しようとしたが、私はdfにエラー

答えて

2

いくつかのポイントを受け取ったUSAMap領域の外側です。 map_exの灰色領域をx軸とy軸の範囲をUSAMap軸の範囲の同じ値に設定することができます。

df <- data.frame(Current_zip_code=c(27103, 27540, 32669, 32765, 39180, 39553, 
47403, 70118, 70119, 70364, 74114, 74133, 83703, 90045, 90263, 90278, 96706, 
96707, 99506), total=c(1, 5, 7, 12, 15, 6, 17, 31, 12, 13, 6, 4, 4, 25, 41, 
65, 33, 25, 22), latitude=c(36.066545, 35.643545, 29.640613, 28.656375, 32.292761, 
30.400599, 39.121719, 29.952305, 29.974504, 29.626988, 36.126894, 36.04309, 
43.668396, 33.960041, 34.035087, 33.871214, 21.338055, 21.345535, 61.224384), 
longitude=c(-80.30733, -78.83486, -82.59446, -81.21026, -90.87184, -88.65092, 
-86.57409, -90.12347, -90.08747, -90.72076, -95.94657, -95.88417, -116.25707, 
-118.3949, -118.70752, -118.37177, -158.02499, -158.08587, -149.77461)) 

library(ggmap) 
usa_center <- as.numeric(geocode("United States")) 
usa_center_map <- get_googlemap(center=usa_center, scale=2, zoom=4) 
USAMap <- ggmap(usa_center_map, extent="normal") 

# Get axes range of USAMap 
axis_range <- attr(usa_center_map, "bb") 

# Set axes range using the "limits" option of 
# scale_x_continuous and scale_y_continuous 
map_ex <- USAMap + 
    geom_point(aes(x=longitude, y=latitude), data=df, 
        col="orange", alpha=0.4, size=df$total*.2) + 
    scale_size_continuous(range=range(df$total)) + 
    scale_x_continuous(limits=c(axis_range$ll.lon,axis_range$ur.lon)) + 
    scale_y_continuous(limits=c(axis_range$ll.lat,axis_range$ur.lat)) 
map_ex 

enter image description here

そうしないと、df内のすべての点が含まれて大きなマップをダウンロードすることができます。

us_map <- get_googlemap(center=c(-110,45), scale=2, zoom=3, size = c(640, 500)) 
map_ex <- ggmap(us_map) + 
    geom_point(aes(x=longitude, y=latitude), data=df, 
        col="orange", alpha=0.4, size=df$total*.2) + 
    scale_size_continuous(range=range(df$total)) 
map_ex 

enter image description here

+0

このコードのためにどうもありがとうございました!しかし、私はアラスカやハワイのプロットを見ることはできません。最後の3つのデータレコードにはこれらの状態のプロットがあります。それを編集するにはどうしたらいいですか? – Walker

関連する問題