0

我正在做一个项目,我想使用 ggplot 或 ggmap 显示“仅”美国东北部(我们可以使用纽约市作为我们的中心)。

我找到纽约州的 x 和 y 并想为两个轴创建范围 +/- 10 度,但不知道如何使 ggmap 只显示我希望它显示的区域。我一直得到整张地图或只有一点......请帮助......谢谢!

which(usa1$stateName == "new york")
ny.x = usa1$x[which(usa1$stateName=="new york")]
ny.y = usa1$y[which(usa1$stateName=="new york")]
ny.x1 = xlim(ny.x -10, ny.x+10)
ny.y1 = ylim(ny.y -10, ny.y+10)

us.map.zm <- ggplot(usa1, aes(map_id = stateName))
us.map.zm <- us.map.zm + geom_map(map =usa, aes(fill = usa1$Murder),fill="white",color ="black") + ylim(ny.y-10, ny.y+10) + xlim(ny.x-10,ny.x+10)
us.map.zm <- us.map.zm + geom_point(data=usa1,aes(x = usa1$x, y = usa1$y,size=usa1$POP17, color="blue"))
us.map.zm <- us.map.zm + coord_map() + ggtitle("Northeast US Populaton vs Murder rate")
us.map.zm
4

1 回答 1

2

添加经纬度限制

 lat <- c(23.49, 34.5)                
    lon <- c(12.33, 21.36)   

    ### Get a map
    map <- get_map(location = c(lon = mean(lon), lat = mean(lat)), zoom = 12,
                   maptype = "satellite", source = "google")

    ### When you draw a figure, you limit lon and lat.      
   us.map.zm <- ggmap(map)+
           scale_x_continuous(limits = c(11.33, 11.36), expand = c(0, 0)) +
           scale_y_continuous(limits = c(44.49, 44.5), expand = c(0, 0))

根据您的要求更改和使用它

于 2018-10-12T07:29:07.330 回答