Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 扩大ggmap输出,消除灰色_R_Ggmap - Fatal编程技术网

R 扩大ggmap输出,消除灰色

R 扩大ggmap输出,消除灰色,r,ggmap,R,Ggmap,有人能帮助我扩展ggmap输出吗 我用它作为模型来制作我自己的地图 虚拟数据: 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, 1

有人能帮助我扩展ggmap输出吗

我用它作为模型来制作我自己的地图

虚拟数据:

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))

但是我收到一个错误

df
中的一些点在
USAMap
区域之外。 可以在
map\u 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
中的一些点位于
USAMap
区域之外。 可以在
map\u 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

非常感谢您提供此代码!但我似乎看不到阿拉斯加或夏威夷的地块。最后三个数据记录在这些状态下有曲线图。我如何编辑它以包含它们?非常感谢您的代码!但我似乎看不到阿拉斯加或夏威夷的地块。最后三个数据记录在这些状态下有曲线图。我如何编辑它们以包含它们?
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