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

Panel Grid Aesthetics Can't be Changed for theme_classic #1555

Closed
DarioS opened this issue Feb 22, 2016 · 3 comments
Closed

Panel Grid Aesthetics Can't be Changed for theme_classic #1555

DarioS opened this issue Feb 22, 2016 · 3 comments

Comments

@DarioS
Copy link

DarioS commented Feb 22, 2016

It has no effect for theme_classic

ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_classic() + theme(panel.grid.major.y = element_line(colour = "pink", size = 4))

but it does work for the other themes

ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_bw() + theme(panel.grid.major.y = element_line(colour = "pink", size = 4))

It also doesn't work for the grid lines perpendicular to the x-axis.

@Katiedaisey
Copy link
Contributor

Since panel.grid.major.y inherits from panel.grid.major while the later has an element_blank class, it will not inherit the desired element_line. This can easily be confirmed via

calc_element('panel.grid.major.y', theme_classic() + theme(panel.grid.major.y = element_line(colour = "pink", size = 4)), verbose = T)

This will happen whenever a new element inherits from a element that was declared blank in the base theme. For instance, adding tick marks only on x with theme_minimal also fails:

ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_minimal() + theme(axis.tick.x = element_line(colour = "pink", size = 4))

It seems these might actually not work in only three cases in which case I would suggest just updating the two themes, classic and minimal, by declaring the problem children.

theme_classic2 <- function(base_size = 12, base_family = ""){
  theme_bw(base_size = base_size, base_family = base_family) %+replace%
    theme(
      panel.border     = element_blank(),
      axis.line        = element_line(colour = "black"),
      panel.grid.major = element_line(),
      panel.grid.major.x = element_blank(),
      panel.grid.major.y = element_blank(),
      panel.grid.minor = element_blank(),
      panel.grid.minor.x = element_blank(),
      panel.grid.minor.y = element_blank(),
      strip.background = element_rect(colour = "black", size = 0.5),
      legend.key       = element_blank()
    )
}

theme_minimal2 <- function(base_size = 12, base_family = "") {
  # Starts with theme_bw and then modify some parts
  theme_bw(base_size = base_size, base_family = base_family) %+replace%
    theme(
      legend.background = element_blank(),
      legend.key        = element_blank(),
      panel.background  = element_blank(),
      panel.border      = element_blank(),
      strip.background  = element_blank(),
      plot.background   = element_blank(),
      axis.ticks        = element_line(),
      axis.ticks.x     = element_blank(),
      axis.ticks.y     = element_blank(),
      axis.ticks.length = unit(0, "lines")
    )
}

@hadley
Copy link
Member

hadley commented Feb 24, 2016

@Katiedaisey would you be interested in doing a PR to make those changes? I'd really appreciate it.

@Katiedaisey
Copy link
Contributor

@hadley Sure. Just let me check those are indeed the only conflicts and I'll send you one tomorrow.

Katiedaisey added a commit to Katiedaisey/ggplot2 that referenced this issue Feb 24, 2016
addresses issue tidyverse#1555 - elements added in new theme inherit "element_blank"
@hadley hadley closed this as completed in f5cc768 Feb 24, 2016
hadley added a commit that referenced this issue Feb 24, 2016
This was referenced Mar 10, 2016
turfed added a commit to lindanlee/PETS2017-paper that referenced this issue May 12, 2016
The default axis tick lengths changed, leading to lots of extra
whitespace around the graph.

"Panel Grid Aesthetics Can't be Changed for theme_classic"
tidyverse/ggplot2#1555
thomasp85 added a commit that referenced this issue Sep 21, 2016
Fixes #1555, #1557, #1565, and #1567

* Add inherit.blank argument to element constructors

* Look for inherit.blank when combining

* Set inherit.blank = TRUE automatically when theme is complete
@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants