Search code examples
rstamen-maps

Mark the center of state in stamen maps


I want to draw a map like the below picture of untitled state and show the center of all state by a colorful circle.

There is google map API which can use in R.But it seems that it's no longer available to use free of charge.

How can I draw this picture by Stamn Maps library in R? If there is a good tutorial about Stamn Maps, I'll appreciate any helps.

enter image description here

thanks for your answers I find one of the solutions that shows map in r by Stamn Maps

d <- data.frame(lat = state.center$y,
                lon = state.center$x)
#-128.5, 27.5, -69, 49
US <- get_stamenmap(bbox = c(left = -128.5, bottom = 27.5, right =
                               -68, top = 50) ,zoom = 4, maptype = c("terrain",
                                                                                 "terrain-background", "terrain-labels", "terrain-lines", "toner",
                                                                                 "toner-2010", "toner-2011", "toner-background", "toner-hybrid",
                                                                                 "toner-labels", "toner-lines", "toner-lite", "watercolor"),
                    crop = TRUE, messaging = FALSE, urlonly = FALSE,
                    color = c("color", "bw"), force = FALSE, where = tempdir())


p <- ggmap(US, base_layer = ggplot(data = d)) +
  geom_point(aes(x = lon, y = lat), color = "blue", size = 2, alpha = 0.5)
p

Solution

  • A minimal example to kickstart your journey:

    set.seed(1702)
    points <- data.frame(lon = rnorm(10, -95.4, 0.1),
                         lat = rnorm(10, 29.7, 0.1))
    
    # get_stamenmap() defaults to the map of Houston, TX if there 
    # is no boundary box defined in the form of:
    # c(lon_min, lat_min, lon_max, lat_max)
    # For more information see ?get_stamenmap
    ggmap(get_stamenmap()) +
        geom_point(data = points,
                   aes(lon, lat), 
                   color = "red")
    

    1