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

Closed
clauswilke opened this issue Nov 9, 2018 · 4 comments
Closed

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

clauswilke opened this issue Nov 9, 2018 · 4 comments

Comments

@clauswilke
Copy link
Member

@clauswilke 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:

library(ggplot2)

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

cowplot::plot_grid(
  p + coord_fixed() + theme(panel.grid.minor = element_blank()) +
    ggtitle("coord_fixed()"),
  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:

ggplot2/R/sf.R

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.

@thomasp85
Copy link
Member

@thomasp85 thomasp85 commented Jan 15, 2019

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

@yutannihilation
Copy link
Member

@yutannihilation yutannihilation commented Jan 15, 2019

+1

@clauswilke
Copy link
Member Author

@clauswilke clauswilke commented Jan 29, 2019

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

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
@lock
Copy link

@lock 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. https://reprex.tidyverse.org/

@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.
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants