Skip to content

Add inherit.blank argument to element constructors #1754

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

Merged
merged 10 commits into from
Sep 21, 2016

Conversation

thomasp85
Copy link
Member

This PR is an alternative fix to #1555, #1557, #1565, and #1567 compared to #1581.

It will propose the inclusion of an inherit.blank argument to the element_* constructors. The reason for this is that we might want to suppress drawing of a parent element and all its children, and then reenable some of the children again. This requires element calculation to sometimes ignore element_blank() and sometimes not. The default should be inherit.blank = FALSE while elements in the included themes should have inherit.blank = TRUE instead.

@hadley
Copy link
Member

hadley commented Sep 16, 2016

This seems like a reasonable approach to me

@thomasp85
Copy link
Member Author

@hadley can you review?

Now you can do stuff like this (not a beautiful plot but an example):

p + theme_minimal() + theme(line = element_blank(), axis.line.y = element_line())

rplot

@hadley
Copy link
Member

hadley commented Sep 17, 2016

What if we automatically set inherit.blank if complete = TRUE in theme()?

@@ -13,6 +13,8 @@
#' @param fill Fill colour.
#' @param colour,color Line/border colour. Color is an alias for colour.
#' @param size Line/border size in mm; text size in pts.
#' @param inherit.blank Should this element inherit the existence of an
#' element_blank among its parents?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you expand on this a little bit? I assume if it's TRUE the "blank-ness" will be inherited, otherwise it will skip the parent and look at the grand parent?


if (is.null(e2) || inherits(e1, "element_blank")) return(e1)
# If e1 is NULL inherit everything from e2
if (is.null(e1)) return(e2)
# If e1 is NULL, or if e2 is element_blank, inherit everything from e2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment needs updating too, right?

@thomasp85 thomasp85 self-assigned this Sep 17, 2016
@Katiedaisey
Copy link
Contributor

Katiedaisey commented Sep 20, 2016

Edit: Just saw you updated your repo, but the following has not changed. Can you confirm my first example with your local branch?

I like this idea. It would prevent the recursive checking that #1581 requires, but your example doesn't seem to work for me.

ggplot(mtcars, aes(wt, mpg)) + geom_point() + theme_minimal() + theme(line = element_blank(), axis.line.y = element_line())

rplot

When I examine the plot theme, it seems line = element_blank() rewrites element_line() and so axis.line.y calls all NULLS. Redoing this with theme(axis.line = element_blank(), axis.line.y = element_line() also results in all NULLS.

When I try p + theme_minimal() + theme(axis.line = element_blank(), axis.line.y = element_line(color = "red")), I get:

rplot04

Examining the plot, I see axis.line.y has color = "red" but isn't printing.

$ axis.line.y          :List of 4
  ..$ colour  : chr "red"
  ..$ size    : NULL
  ..$ linetype: NULL
  ..$ lineend : NULL
  ..- attr(*, "class")= chr [1:2] "element_line" "element"

Also, currently theme_classic() doesn't inherit correctly.
rplot01

@thomasp85
Copy link
Member Author

This has been fixed I think - truly with the latest version

@thomasp85
Copy link
Member Author

I cannot confirm any problems and all changes has been pushed - can you try again and make sure you create the plot object from scratch

@hadley
Copy link
Member

hadley commented Sep 20, 2016

LGTM

@Katiedaisey
Copy link
Contributor

@thomasp85 Sorry, I previewed the comment but apparently never posted it. Yes, I've found no problems with the last update!

@lock
Copy link

lock bot commented Jan 18, 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 Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants