Skip to content

coord_sf() drops axis labels if graticules don't extend all the way to the plot boundary #2985

Closed
@clauswilke

Description

@clauswilke

In ggplot2 3.1.0, coord_sf() drops axis labels if graticules don't extend all the way to the plot boundary. This is a regression from 3.0.0. A reprex follows.

library(ggplot2)

world <- sf::st_as_sf(rworldmap::getMap(resolution = "low"))
ggplot(world) + geom_sf() + theme_bw() + coord_sf()

ggplot(world) + geom_sf() + theme_bw() + coord_sf(expand = FALSE)

Created on 2018-11-08 by the reprex package (v0.2.1)

This bug was introduced by me when I wrote code such as the following, to calculate intersection points between the graticules and the plot boundaries:

ggplot2/R/sf.R

Line 592 in 15ddc22

id1 <- c(id1, which(graticule$type == panel_params$label_axes$top & graticule$y_start > 0.999))

I did not consider that the plot range could extend beyond the physical limits of the earth. I'll have to ponder what the options are. One option might be to make the tolerance configurable. (I hardcoded 0.001.) Another option might be to base the tolerance on the expansion factors used for the x and y scales.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorcoord 🗺️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions