woshitom
woshitom

Reputation: 5141

R plotly, zoom on a choropleth map

In R using plotly i'm displaying the map of Asia using:

plot_ly (type = 'choropleth') %>% 
layout ( geo = list ( scope = 'asia' ))

Any idea how can I only display (I assume by zooming) the map of south east asia?

Upvotes: 1

Views: 2402

Answers (1)

Salim B
Salim B

Reputation: 2719

Unfortunately there's no way to let plotly automatically scale/zoom the map to display only a section with specific countries. But you can manually define the desired map section by using the lonaxis and lataxis layout parameters:

plot_ly(type = 'choropleth') %>% 
  layout(geo = list (scope = 'asia',
                     lonaxis = list(range = c(90, 150)),
                     lataxis = list(range = c(-15, 30))))

This produces the following map section which should cover Southeast Asia pretty well: Southeast Asia

You might have to play around a little with those values to exactly meet your needs. According to the plotly reference the values are set in degrees. But keep in mind that the appropriate values depend on the projection type set via layout(geo = list(projection = list(type = "...")), so if you change the projection type, you'll probably have to adjust the lonaxis and lataxis ranges as well.

Furthermore you can zoom the map in and out by setting a value between 0 and 10 in layout(geo = list(projection = list(scale = ...)).

Upvotes: 1

Related Questions