-
Notifications
You must be signed in to change notification settings - Fork 678
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
Theme guidelines for developers of extension packages #171
Labels
Comments
I just saw that there is already some existing text on this topic. I may take a stab editing it along the lines of this issue. |
@thomasp85 Regarding my point 2 above, I suggest something like the following to explain the issue. The main goal for theme developers should be to write themes that behave similarly to the default. library(ggplot2)
df <- data.frame(x = 1:3, y = 1:3)
base <- ggplot(df, aes(x, y)) + geom_point()
mytheme <- theme_classic() +
theme(
axis.line.x = element_line(color = "red"),
axis.line.y = element_line(color = "blue")
)
base + mytheme # doesn't work, lines are not removed
base + mytheme + theme(axis.line = element_blank()) mytheme2 <- theme_classic() %+replace%
theme(
axis.line.x = element_line(color = "red"),
axis.line.y = element_line(color = "blue"),
complete = TRUE
)
# works as before
base + mytheme2 # now also works
base + mytheme2 + theme(axis.line = element_blank()) Created on 2019-12-17 by the reprex package (v0.3.0) |
djnavarro
added a commit
to djnavarro/ggplot2-book
that referenced
this issue
Jun 17, 2021
djnavarro
added a commit
that referenced
this issue
Feb 8, 2023
* adds detail to the ggproto introduction * expands the explanation of ggproto syntax * converts ggproto style guide to bulleted list * foreshadows the output format when ggproto methods are printed * attempts to structure final part as "advanced topics" * tweaks comment on stateless ggproto objects * starts extending "new themes" section * comments out bad example * adds section on complete themes per suggestion in #171 * starts section on registering new theme elements * temporary fix to the register_theme_element() bug * includes the stat_chull() example in new stat section * adds the stat_density_common() example * adds setup_data example for geom_spike * use geom_barbell to illustrate combining geoms * typo * edits new coords section * adds the scale_fill_random example * adds facet_scatter() example * tidies facet_scatter example * start position_jitternormal example * tidies the jitternormal example * typo fix * use fewer columns in code to avoid bs4_book display issue * smoothes geom_barbell() text * apply typo fixes from code review Co-authored-by: Thomas Lin Pedersen <thomasp85@gmail.com> * typo fix Co-authored-by: Thomas Lin Pedersen <thomasp85@gmail.com> * switch to third person pronouns * removes comment on performance * typo fix * minor tweaks * whitespace tweaks * whitespace and comment capitalisation fixes * fixes linewidth/size warning in extensions --------- Co-authored-by: Thomas Lin Pedersen <thomasp85@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be good to provide some guidelines for developers adding themes to their extension packages. I suggest the following four points. It doesn't have to add a lot of text to the book.
Always define your theme by starting from an existing theme.
Use
%+replace%
, not+
, to modify the starting theme, and setcomplete = TRUE
.Don't overwrite the default theme.
If your extension package defines new theme elements (new in ggplot 3.3.0), add them to the default theme. As an example of a user-defined new theme element, consider using the code in this comment.
The text was updated successfully, but these errors were encountered: