Why coord_map() overrides dup_axis() in ggplot and how to work around it

Viewed 98

I'm a little puzzled with the behavior of ggplot2::coord_map(). Concretely I would like to know why it seems to override ggplot2::dup_axis() and how can I work around it.

Let's have a look with the following reproducible examples:

Example 1: Using ggplot2::dup_axis() to obtain lat/long axis all around the map:

ggplot2::ggplot(ggplot2::map_data("france")) +
  ggplot2::geom_polygon(ggplot2::aes(x = long, y = lat, group = group),
                        color = "black",
                        fill = "white",
                        size = .2) +
  ggplot2::scale_y_continuous(sec.axis = ggplot2::dup_axis()) +
  ggplot2::scale_x_continuous(sec.axis = ggplot2::dup_axis())

enter image description here

Example 2: Using ggplot2::coord_map() to avoid distortions:

ggplot2::ggplot(ggplot2::map_data("france")) +
  ggplot2::geom_polygon(ggplot2::aes(x = long, y = lat, group = group),
                        color = "black",
                        fill = "white",
                        size = .2) +
  ggplot2::coord_map()

enter image description here

Example 3: Using both ggplot2::dup_axis() and ggplot2::coord_map() to duplicate axis while avoiding distortions:

ggplot2::ggplot(ggplot2::map_data("france")) +
  ggplot2::geom_polygon(ggplot2::aes(x = long, y = lat, group = group),
                        color = "black",
                        fill = "white",
                        size = .2) +
  ggplot2::scale_y_continuous(sec.axis = ggplot2::dup_axis()) +
  ggplot2::scale_x_continuous(sec.axis = ggplot2::dup_axis()) +
  ggplot2::coord_map()

enter image description here

The goal would be to be able to produce maps formatted as the one in example 1 but using ggplot2::coord_map() to avoid distortions. All approaches to work around this issue are welcome.

0 Answers
Related