Learn R Programming

plotly (version 4.10.4)

plot_mapbox: Initiate a plotly-mapbox object

Description

Use this function instead of plot_ly() to initialize a plotly-mapbox object. This enforces the entire plot so use the scattermapbox trace type, and enables higher level geometries like add_polygons() to work

Usage

plot_mapbox(data = data.frame(), ...)

Arguments

data

A data frame (optional).

...

arguments passed along to plot_ly(). They should be valid scattermapbox attributes - https://plotly.com/r/reference/#scattermapbox. Note that x/y can also be used in place of lat/lon.

Author

Carson Sievert

See Also

plot_ly(), plot_geo(), ggplotly()

Examples

Run this code
if (FALSE) {

plot_mapbox(res_mn)
plot_mapbox(res_mn, color = ~INDRESNAME)

map_data("world", "canada") %>%
  group_by(group) %>%
  plot_mapbox(x = ~long, y = ~lat) %>%
  add_polygons() %>%
  layout(
    mapbox = list(
      center = list(lat = ~median(lat), lon = ~median(long))
    )
  )
}

Run the code above in your browser using DataLab