How do I get plotly choropleth map locations to focus on Europe or certain European countries?

I am following the code from this website and trying to plot some data on an interactive map using ploty. Difference is I only have data for 6 euro pean countries. Currently the map is plotting for the entire world. How do I adjust the code to zoom in on either all of Europe or just the 6 European countries in the data. See sample code below. The country codes are from thislink.

# Libraries
library(tidyverse)
library(plotly)

# Data
countries <- c("Germany", "Belgium", "Framce", "Italy", "Spain", "Poland")
codes     <- c("DEU", "BEL", "FRA", "ITA", "ESP", "POL")
values    <- c(100, 200, 300, 400, 500, 600)

df <- tibble(countries, codes, values)

# Maps
plot_geo(locations = df$codes) %>% 
    add_trace(
        z = ~values,
        locations = ~codes,
        color = ~values
    )

You can specify the lat and lon range for the initial zoom using the layout() function.

# Maps
plot_geo(locations = df$codes) %>% 
  add_trace(
    z = ~values,
    locations = ~codes,
    color = ~values
  ) %>%
  layout(
    geo = list(lonaxis = list(range = c(-15, 30)),
               lataxis = list(range = c(35, 60))
               )
    )

1 Like

@scottyd22 Thanks. Can I ask how you figured out the latitude and longitude co-ordinates?

I Google'd "lat lon of europe" and then adjusted from there.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.