I was working on a project where I want to use ggplot or ggmap to show 'only' the northeast part of the US (we can use NYC as our center).
I locate the x and y of NY state and want to create the range for both axis +/- 10 degree, but did not know how to make the ggmap only shows the area i want it to show. I kept getting either the whole map or only a point...please help...thank you!!!
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
Add the latitude and longitude limit
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))
Alter and use this as you per your requirements