扩展 ggmap 输出并摆脱灰色

Expanding ggmap output and getting rid of grey

任何人都可以协助扩展我的 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))

输出地图偏离中心。有什么方法可以扩大它以包括我们在阿拉斯加和夏威夷的朋友吗?我不喜欢灰色背景和轴标题。有什么方法可以扩展和摆脱灰色和轴?

我试过添加这个

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

但是我收到一个错误

df 中的某些点在 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

否则,您可以下载包含 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