Aim: I am trying to create an interactive version of a ggplot2 map using plotly (via ggplotly).
Problem: Plotly adds additional space above and below the chart rather than "stretching" the chart like it should (see images for example).
Example
What I want (example made in ggplot2):
What I'm getting (example made in plotly):
I understand that aspect.ratio is not supported in ggplotly but is there any other way to remove the space above and below whilst keeping the x-axis (-12,2) and y-axis (50,60) limits as they are
Code:
library(maps)
library(ggplot2)
library(plotly)
boundaries <- ggplot2::map_data("world", region=c("UK","Ireland","France","Norway"))
map <- ggplot() +
geom_polygon(data=boundaries, aes(x=long, y=lat, group=group), color="black", fill="white") +
coord_sf(xlim=c(-12, 2), ylim=c(50,60)) +
theme(aspect.ratio = 1.2)
show(map)
visual <- ggplotly(map, height=1.2*400, width=400, tooltip=c("text"), hoverinfo='hide',
dynamicTicks=F) %>%
layout(xaxis=list(autorange=F, range=c(-12, 2)), yaxis = list(autorange=F, range=c(50,60)))
show(visual)
To replicate the problem:
OS: Windows 10
IDE: RStudio
R: R 3.6.1