Reputation: 1983
I try making maps using plotly, with plot_ly the result is great, but I found I should be using plot_geo, but can't manage to make it works.
I work with a France map in Lambert93 :
library(plotly)
download.file("https://www.data.gouv.fr/fr/datasets/r/087ab701-f21d-4046-b53e-8b647baf505d","dep.geojson")
dep <- sf::st_read("c:/users/sdaubree/Desktop/testplotly/101deps-lambert.geojson")
that plot correctly with plot_ly :
plot_ly(dep)
But not correctly with plot_geo :
plot_geo(dep)
As you can see, France is too wide this way.
I tried to change the CRS, as plot_geo give me the following message : The trace types 'scattermapbox' and 'scattergeo' require a projected coordinate system that is based on the WGS84 datum (EPSG:4326), but the crs provided is: '+proj=lcc +lat_0=46.5 +lon_0=3 +lat_1=49 +lat_2=44 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs'. Attempting transformation to the target coordinate system.
So I try to change the CRS myself :
dep84 <- sf::st_transform(dep,sp::CRS("EPSG:4326"))
plot_geo(dep84)
But it changes nothing to the result : France is still flat.
Upvotes: 0
Views: 412
Reputation: 5499
This might be a problem with plot_geo()
's default projection, and zooming in on northern latitudes. There seems to be more than one way to fix this by changing arguments in a call to 'layout()`. A couple of them below:
# 1. by using scope
plot_geo(dep) %>%
layout(geo = list(scope="europe"))
# 2. by changing projection type
plot_geo(dep) %>%
layout(geo = list(projection=list(type = 'natural earth1')))
Both pretty are narrower than the default. The 'wider' of the two ('natural earth1'):
Changing the crs of the objet wasn't necessary. A list of plotly projections if you want to find another.
The scope
argument accepts either continent names or 'world' as far as I can tell.
Upvotes: 2