I have created a map using get_map and ggmap) that includes points reflecting bird diversity and richness. I want to crop the resulting map to only include certain bounds of latitude and longitude, but when I try to use the xlim() and ylim() functions, the map itself vanishes.
This code is used to create my map with data points.
Detroit_MI_Map_MCK <- get_map(location = c(lon = -83.10484, lat = 42.34633), zoom = 16, source = "google", maptype = "satellite")
MCK_SITE_MAP <- ggmap(Detroit_MI_Map_MCK, x = Longitude, y = Latitude, label = AUDIOMOTH_BirdStats_Local$AudioMoth)
MCK_Map <- MCK_SITE_MAP +
geom_point(data = AUDIOMOTH_BirdStats_Local, alpha = 1.0, aes(x = AUDIOMOTH_BirdStats_Local$longitude, y = AUDIOMOTH_BirdStats_Local$latitude, color = Richness, size = Shannon)) +
geom_label_repel(data = AUDIOMOTH_BirdStats_Local,aes(x = AUDIOMOTH_BirdStats_Local$longitude, y = AUDIOMOTH_BirdStats_Local$latitude, label = AUDIOMOTH_BirdStats_Local$AudioMoth), position = position_dodge(width = 1), size = 4) +
scale_color_gradient(low = "red", high = "springgreen3") +
scale_size(range = c(4,10))
However, when I try to add xlim and ylim to focus on the MCK points, the map disappears:
lat_MCK <- c(42.342, 42.350)
lon_MCK <- c(-83.100, -83.108)
MCK_Map +
xlim(lon_MCK) +
ylim(lat_MCK)
Result after attmpeting xlim and ylim
Any assistance on how to fix this problem would be greatly appreciated!