如何使用限制(xlim 和 ylim)在 R (ggplot/ggmap) 中放大到美国东北部地区?

How to zoom in to the north east area of US in R (ggplot/ggmap) with limit (xlim and ylim)?

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

我找到了纽约州的 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

添加经纬度限制

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

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