Skip to content

Controlling graticule appearance with geom_sf #2389

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

Closed
GillesSanMartin opened this issue Jan 8, 2018 · 3 comments
Closed

Controlling graticule appearance with geom_sf #2389

GillesSanMartin opened this issue Jan 8, 2018 · 3 comments
Labels
bug an unexpected problem or unintended behavior themes 💃
Milestone

Comments

@GillesSanMartin
Copy link

The control of the appearance (color, linewidth, linetype...) of the graticule produced with geom_sf is quite counter-intuitive and something seems to be wrong.

For the examples below I used the latest ggplot2 version from github reinstalled today (2.2.1.9000) and sf 0.5-4 (with R version 3.4.3 - Ubuntu 16.04.3 LTS).
This issue was initially posted on the sf github repository

I expected to be able to control for example the color and linetype of the graticule with panel.grid but these commands seem to be ignored

library(ggplot)
library(sf)
nc = st_read(system.file("gpkg/nc.gpkg", package = "sf")) 

ggplot() + 
    geom_sf(data = nc) + 
    theme(panel.grid = element_line(color = "red", linetype = 2))

rplot001

It works as expected with panel.grid.major (but I would expect that panel.grid.major will inherit from panel.grid)

ggplot() + 
    geom_sf(data = nc) + 
    theme(panel.grid.major = element_line(color = "red", linetype = 2))

rplot001

If you want to change only -say- the x grid color with panel.grid.major.x both x and y are changed :

ggplot() + 
    geom_sf(data = nc) + 
    theme(panel.grid.major.x = element_line(color = "red", linetype = 2))

rplot001

If you want to change both x and y in different ways nothing happens :

ggplot() + 
    geom_sf(data = nc) + 
    theme(panel.grid.major.x = element_line(color = "red", linetype = 2),
          panel.grid.major.y = element_line(color = "blue", linetype = 3))

rplot001

Each example works as intended when I use another geom :

d <- data.frame(x = rnorm(10), y = rnorm(10))
p <- ggplot(d, aes(x,y)) + geom_point()
p + theme(panel.grid = element_line(color = "red",  linetype = 2))
p + theme(panel.grid.major = element_line(color = "red",  linetype = 2))
p + theme(panel.grid.major.x = element_line(color = "red",  linetype = 2))
p + theme(panel.grid.major.x = element_line(color = "red", linetype = 2),
          panel.grid.major.y = element_line(color = "blue", linetype = 3))

By the way, if I'm not wrong, a few weeks ago (30 november) the default color of the graticule was also much lighter and less conspicuous (better to my taste)

@cpsievert
Copy link
Contributor

Looks like this regression was introduced in caca650.

There's a chance that it has other unintended consequences due to the fact that ggplot2:::plot_theme(qplot(1:10))$panel.grid.major is now NULL

@hadley
Copy link
Member

hadley commented Jan 24, 2018

Thanks - I must be accessing directly rather than using the theme inheritance system.

@hadley hadley added bug an unexpected problem or unintended behavior themes 💃 labels Apr 26, 2018
@hadley hadley added this to the v2.3.0 milestone Apr 26, 2018
@hadley hadley closed this as completed in 039d38f May 1, 2018
@lock
Copy link

lock bot commented Oct 29, 2018

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 Oct 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior themes 💃
Projects
None yet
Development

No branches or pull requests

3 participants