-
Notifications
You must be signed in to change notification settings - Fork 2.1k
theme: Add different ticks length for different axes #2934
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
Conversation
Hi @pank, Would you mind opening up a fresh issue for this? That way logistics/changes, etc. can be discussed without cluttering the PR itself. Thanks! PS As for styling, you can use the styler package to implement the in-house style as described in the tidyverse style guide. |
I've wanted this option in the past, so I'd generally be in favor. Not sure if it can be done without the clutter of adding all these new theme elements. For the theme calculation code, you could probably just write: theme$axis.ticks.length.x.bottom <- theme$axis.ticks.length.x.bottom %||% theme$axis.ticks.length.x %||% theme$axis.ticks.length
theme$axis.ticks.length.x.top <- theme$axis.ticks.length.x.top %||% theme$axis.ticks.length.x %||% theme$axis.ticks.length
theme$axis.ticks.length.y.left <- theme$axis.ticks.length.y.left %||% theme$axis.ticks.length.y %||% theme$axis.ticks.length
theme$axis.ticks.length.y.right <- theme$axis.ticks.length.y.right %||% theme$axis.ticks.length.y %||% theme$axis.ticks.length Slightly less efficient, but also less cluttered and easier to read. Don't worry about making multiple git commits into the same PR, they'll all be combined into one upon merge. |
@clauswilke can you have a look at this one |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good to me. I left a few specific comments.
NEWS.md
Outdated
@@ -104,6 +104,10 @@ This is a minor release and breaking changes have been kept to a minimum. End us | |||
`nlevel`, an alias for `scaled`, to better match the syntax of `stat_bin()` | |||
(@bjreisman, #2679). | |||
|
|||
* New theme elements allowing different ticks lengths for each | |||
axis. For instance, this can be used to have inwards ticks on the | |||
x-axis (`axis.ticks.length.x`) and and outwards ticks on the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an extra "and" here.
#' axis.ticks.length.y = unit(.25, "cm"), | ||
#' axis.ticks.length.x = unit(-.25, "cm"), | ||
#' axis.text.x=element_text(margin=margin(t=.3, unit="cm")) | ||
#' ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use tidyverse indenting here (2 spaces only) and make sure there are two spaces around each =
. Also, please add a comment explaining what this example shows (inward/outward pointing ticks on x/y axes).
* NEWS.md: Fix typo. * R/theme.r: Fix style and add comments for examples.
Dear Claus, Thanks for the comments. I appreciate you taking the time to review this. Sorry about the silly mistakes. I guess I need to figure out a way to configure ESS to I have pushed a new commit that resolves the language/styles issues. I added a description of the currently-present examples as well. Should I rebase against upstream or does github take care of that aspect? Do I need to click any of the buttons above or will you re-review the patch? Thomas, thanks for revising the PR. A hope you'll both have a nice weekend. Kind regards, |
R/theme.r
Outdated
#' p1 + theme(axis.title.y = element_text(size = rel(1.5), angle = 90)) | ||
#' | ||
#' # Make ticks point outwards on y-axis and upwards on x-axis |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small remaining nitpick: "inwards" instead of "upwards"? x-axis tick marks are always vertical, so arguably they always point up (and down).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have one remaining minor wording issue, otherwise looks good to me.
You don't need to rebase, since github says there is no conflict with the base branch. |
Hi Claus, Do I need to do anything else, e.g. a squash message, or is this sufficient? Thanks, |
NEWS.md
Outdated
* New theme elements allowing different ticks lengths for each | ||
axis. For instance, this can be used to have inwards ticks on the | ||
x-axis (`axis.ticks.length.x`) and outwards ticks on the y-axis | ||
(`axis.ticks.length.y`). (@pank, #2935) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to nitpick, one last request, then I'll merge: Please move the period to after (@pank, #2935)
, just like in the other news bullets.
Ah, well spotted. Thanks a lot! I noticed that the NEWS entry is currently filed under Also, in the corresponding issue, you wrote
Should we leave that for another patch? |
Thanks for noticing. This is actually a problem that needs to be fixed. It seems you're working from an old code base from before the last release. You'll have to rebase to or merge github master and then move your news item to above the 3.1.0 release. Theme inheritance for units should be left to a separate patch, since it would involve a lot of other parts of the code. |
Also use longer lines to somewhat better match other entries.
Indeed. It seems most of the patch is from October, 2018. I just merge upstream |
Thanks! |
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/ |
Hi,
I would like to add support for different ticks length for different axes.
My main motivation is to match an Excel theme that I have been given, which features upwards ticks on the x-axis. I don't want inwards ticks on the y-axis though.
It was first requested in issue #1319.
I have not submitted patches to
ggplot2
before, neither am I too familiar with thetidyverse
style guide normally, nor the github pull interface (I normally usegit format-patch
. If I have broken any conventions let me know and I will try to fix the mistake.It was not clear to me what to do where the names I added were longer than the length of other nearby names. The problem is that the alignment goes wrong.
Here is an example.
Should I,
git blame
...)?Also, I have not used visual tests before, but it seems to work. (I just ran
devtools::test()
and saw no more errors; the documentation is a bit sparse on visual tests).Finally, this bit is pretty crude:
I just followed the example of
legend.spacing.x
, but if desired I can try to cut it down.Below is a minimal example of a somewhat of useful thing that could be done after applying the patch. Notice the ticks on the button is sort-of enclosing the bar and the ones on the right axis serve as an explanation of the graph. (I'm not saying this is the best way to explain what is going on in this graph!)
Thanks,
Rasmus