plotly / plotly/plotly.R

Aspect ratio of geom_map is distorted after conversion to plotly

Open
#1,797 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

Disclaimer: This is a x-post from stackoverflow, but the longer I ponder around this issue, the more I think, this might be a bug.

I am trying to create an interactive map of Germany with plotly and ggplot. At last, I'd like to overlay geom_points with tooltips, but so far I am struggeling with the aspect ratio.

I create the plot like this:

library(tidyverse)
library(ggplot2)
library(plotly)

p <- map_data("world") %>%
  filter(region=="Germany") %>%
  ggplot(aes(x=long, y = lat, group = group)) +
  geom_polygon(fill="grey") +
  coord_map()

When simply plotting it with ggplot, the aspect ratio of Germany is how I know it from school.

p

germany_with_correct_aspect_ration

When converting it to a plotly plot with ggplotly the plot is distorted.

ggplotly(p)

enter image description here

Any ideas how to fix it? I don't know whether this is relevant, but I used to run this code in an R Markdown document.

Thanks a lot.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the R example using map_data("world"), geom_polygon(), coord_map(), and ggplotly() to reproduce the distorted Germany map. Compare the static ggplot output with the converted interactive plot and investigate how the coordinate settings are transferred. Done means the interactive result preserves the original aspect ratio while still supporting the intended overlay and tooltips.

Written by the indexing model from the issue text.

Assessment

Tech stack
plotly, r
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.