13.9 地图上的散点图

plot_mapbox() 使用 Mapbox 提供的地图服务,因此,需要注册一个账户,获取 MAPBOX_TOKEN

data("quakes")
plotly::plot_mapbox(
  data = quakes, colors = "Greys",
  lon = ~long, lat = ~lat,
  color = ~mag, size = 2,
  type = "scattermapbox", 
  mode = "markers",
  marker = list(opacity = 0.5)
) |>
  plotly::layout(
    title = "Fiji Earthquake",
    mapbox = list(
      zoom = 3,
      center = list(
        lat = ~ median(lat - 5),
        lon = ~ median(long)
      )
    )
  ) |>
  plotly::config(
    mapboxAccessToken = Sys.getenv("MAPBOX_TOKEN")
  )

图 13.7: 斐济地震数据