Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coord_sf() doesn't adjust line size for graticule lines #2991

clauswilke opened this issue Nov 9, 2018 · 4 comments · Fixed by #3113

coord_sf() doesn't adjust line size for graticule lines #2991

clauswilke opened this issue Nov 9, 2018 · 4 comments · Fixed by #3113


Copy link

clauswilke commented Nov 9, 2018

Line sizes in themes are generally provide in units of mm and converted to grid units by multiplication by .pt. However, coord_sf() doesn't do that, it uses the value of size directly. Reprex:


df <- data.frame(x = c(1, 2, 3), y = c(1, 2, 3))
p <- ggplot(df, aes(x, y)) + geom_point()

  p + coord_fixed() + theme(panel.grid.minor = element_blank()) +
  p + coord_sf() +
    ggtitle("coord_sf() default"),
  p + coord_sf() + theme(panel.grid = element_line(size = 0.5*.pt)) +
    ggtitle("coord_sf() theme adjusted"),
  nrow = 2

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

The offending lines are here:


Lines 576 to 582 in 6786969

render_bg = function(self, panel_params, theme) {
el <- calc_element("panel.grid.major", theme)
line_gp <- gpar(col = el$colour, lwd = el$size, lty = el$linetype)
grobs <- c(
list(element_render(theme, "panel.background")),
lapply(sf::st_geometry(panel_params$graticule), sf::st_as_grob, gp = line_gp)

The fix is simple, but it would affect the visual appearance of a lot of plots out in the wild.

Copy link

I think this makes sense to change irrespectively of the changes in the wild it may affect... but better wait until the next big(ish) release

Copy link


Copy link
Member Author

There's a somewhat related issue that could be fixed at the same time: #2525

clauswilke added a commit to wilkelab/ggplot2_archive that referenced this issue Feb 1, 2019
clauswilke added a commit that referenced this issue Feb 12, 2019
* Make coord_sf() panel grid mimic coord_cartesian() panel grid. Closes #2991. Closes #2525.

* don't drop gray background

* add unit test

* don't error if line size is undefined
Copy link

lock bot commented Aug 11, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue.

@lock lock bot locked and limited conversation to collaborators Aug 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
None yet

Successfully merging a pull request may close this issue.

3 participants