-
Notifications
You must be signed in to change notification settings - Fork 1
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
new handling of custom geom defaults #81
Conversation
gave up on attempt to build details table in cmapglobals. created them (somewhat duplicatively) in the new `fetch` and `set` fns.
OK, I think I addressed the issue by building the values right in the new |
functions now use name geom in title. now called `fetch_cmap_geom_defaults` and `set...`. The reset of geom defaults in finalize is now much higher in the code where it makes more logical sense, and finalize now has an arg `use_cmap_aes` that allows users to turn off this functionality if desired.
This is ready to be tested and maybe merged? My test code is here. I still need to write documentation for this. I can do that documentation in this branch, or back in the |
added imports for map2 and walk2 from purrr. This creates a series of warnings upon package load about 14 purrr imports being overwritten by functions from rlang and scales.
@nmpeterson thanks for your tweaks. I added documentation and added the
I'm not sure how to handle this... all these packages get loaded in the tidyverse without issue... |
…POS/cmapplot into label_fonts_geomdefaults
I don't get that particular error with
|
Damn. We really can't run any examples that rely on font changes and expect The Purrr error has disappeared for me, too. Must have just been a quirk of the current session I was in. |
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 think I'm fine with this. The one thing I don't like is that, with these functions exposed, if a user were to run set_cmap_geom_defaults()
without first saving the current defaults via fetch_cmap_geom_defaults()
, there is no way to revert the change without reloading cmapplot/ggplot2. Or am I missing something?
@nmpeterson that's correct. Because the risk of screwing it up is not actually that great (restarting the session/reloading the packages), this did not feel like a fatal flaw. That being said, a safer option would certainly be preferable. I am open to other implementations (e.g. automatic caching of the initial defaults somewhere in a global environment) but I do not have the knowledge of R environments to easily implement this. Not sure if you or anyone else want to take a stab at that? |
Any reason not to move the code for Then |
That seems reasonable. I'll give it a try. |
The CMAP defaults could also be saved there instead of in the function definition, in case anybody wanted to tweak them. |
`fetch_` and `set_` are now internal functions. `fetch_` is run `.onLoad`, and values are stored in `cmapplot_globals$geom_defaults`. Running the function on load forced me to simplify the function's `get` call to not specify a package environment, as `ggplot2` is not "attached" within the cmapplot env. Anyway, it seems to still work. `apply_` and `unapply_` are wrappers to `set_`, setting CMAP preferred and cached aesthetics, respectively. `finalize` is updated to utilize the new functions. I was not able to get the CMAP geom values into `cmapplot_globals` (see forthcoming comment).
OK, I have been able to mostly implement the framework recommended by @nmpeterson. See the above commit 79f2202 description, which documents the changes.
EDIT: It's worth noting that I think the right way to handle this is to put those expressions directly into |
this commit also changes the overall nomenclature of this new group of functions to use "default_aes" (following ggplot2) rather than "geom_defaults"
Do you sleep?? |
I've tested all of the latest changes and everything seems to be in order. I've added a few comments that don't impact functionality (see above). |
I've addressed @nmpeterson's comments. Waiting for review from @dlcomeaux before merging into In other news, sometimes when I run
But I don't see that PDF anywhere in the directory. Curious if others see this? |
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.
This seems to work as expected. Matt, you beat me to it on changing that example that Noel suggested - otherwise, I left one small comment about line widths. Great work.
I have had that note before. It doesn't happen every time - I have noticed it when I was doing testing on PDFs. Doesn't seem to cause any issues, but I have not found a way to reliably get rid of it (aside from sometimes just restarting the session). |
This PR is set to merge into #67. The intention is to isolate the setting and resetting of geom defaults into their own functions that can be called not only in
finalize_plot
but also by the user as to have our custom geom defaults impact ggplots pre-the finalize stage.Two new exported functions are created, currently in cmap_ggplot_defaults.R:
fetch_cmap_gg_defaults
returns a named list of all the geom defaults we would seek to overwrite (for replacement later)set_cmap_gg_defaults
sets geom defaults for all the geoms we plan to overwrite. This function will either overwrite with our defaults, or will take the list outputted byfetch
to reset.The general workflow (which is now implemented in
finalize_plot
but can also be implemented by the user) is:To do this, I have created a tibble in
cmapplot_constants
that contains the geoms to overwrite and their preferred values. Here's where things get tricky. Because the preferred values are calculated based on other other cmapplot values and functions (e.g.ggplot_size_conversion
and values fromcmapplot_globals
such as font families and faces) I needed to add this via.onLoad
. This works pretty well, but it's not perfect.It seems to take the size attributes OK, but it leaves fonts as Arial. In other words, even though fonts are set before the tibble is created, the values taken from
cmapplot_globals
are still the old ones, maybe because the version ofcmapplot_globals
available within the.onLoad
environment is still the old one with all fonts set to Arial?This is where I could use some help, probably from @nmpeterson. Am I thinking about this the right way? How would I coax
.onLoad
to fetch the updated fonts? Is there somewhere besides for.onLoad
I should put this?Here's the test code that I've been using:
If we can get this to work, I still need to:
add details for all geoms that need to be overwritten (I think just GeomRecessionsText)test GeomRecessionsText - font family seems to not be sticking.finalize_plot
to ignore the set and reset of geom defaults if the user wantsfinalize_plot
's return of an object (and our documentation says this is the case), confirm that this is actually wrong because what finalize returns is a grid object, not a ggobject. If correct, move the geom reset higher in the code and edit the documentation.