如何通过ggmap基于经纬度坐标获取Stamen黑白地图?
Hey there! I see the issue you're running into—using a state name works perfectly for pulling up that clean Stamen toner-background map, but switching to a coordinate bounding box seems to ignore your maptype and source settings. Let's get this sorted out.
The Root of the Problem
When you pass a raw 4-element vector directly as the location parameter, ggmap::get_map() can sometimes misinterpret the input format. This can lead it to fall back to default map sources instead of honoring your explicit source="stamen" and maptype="toner-background" arguments.
The Fix: Standardize Your Bounding Box
Use ggmap::make_bbox() to explicitly construct a proper bounding box object first. This makes it crystal clear to the function that you're defining a geographic range, ensuring it respects all your specified parameters. Here's the adjusted code:
# First, create a standardized bounding box object my_bbox <- ggmap::make_bbox(left = -120, bottom = -65, right = 5, top = 70) # Call get_map with the structured bbox and explicit parameters map <- ggmap::get_map(location = my_bbox, zoom = 3, maptype = "toner-background", source = "stamen")
Extra Troubleshooting Checks
- Zoom Level Compatibility: Stamen's toner maps have limited tile coverage at very low zoom levels (like zoom=3) for extreme global ranges. If the code above still doesn't work, try adjusting the zoom to 2 or 4 to see if that resolves it.
- Update ggmap: Older versions of the package had quirks with parameter parsing for bounding boxes. Run
update.packages("ggmap")to ensure you're using the latest release.
This should get you that crisp black-and-white map for your specified coordinate range!
内容的提问来源于stack exchange,提问作者Bear Bile Farming is Torture

