IDEMSInternational / R-Instat

A statistics software package powered by R
http://r-instat.org/
GNU General Public License v3.0
38 stars 102 forks source link

Updating geoms for plots #4413

Open rdstern opened 6 years ago

rdstern commented 6 years ago

ggplot2 has an update_geom_defaults command. In the documentation it says:

"Modify geom/stat aesthetic defaults for future plots". Examples include: update_geom_defaults("point", list(colour = "darkblue")) update_geom_defaults("point", list(colour = "black"))

This seems very useful for us. I could certainly have made good use of it recently to help gets some graphs consistent. Surprisingly this command is not in the ggplot2 guide.

I wonder if we could give this as a command, while we wait for a dialogue. I assume the dialogue might be new, or might become part of our themes.

There would be the issue of wanting to be able to reset to the defaults - which is discussed in stack overflow. They suggest saving the existing values first, e.g.

old <- ggplot2:::find_subclass("Geom","line")$default_aes

There is also the ggthemr package that may be useful here - though it is not yet in CRAN. It says:

ggthemr does three different things while setting a theme.

It updates the default ggplot2 theme with the specified ggthemr theme by using the 1) ggplot2::theme_set() function. 2) It modifies the aesthetic defaults for all geoms using the ggplot2::update_geom_defaults() function. 3) It creates functions for all the different scales in the global environment.

dannyparsons commented 6 years ago

update_geom_defaults looks very useful and we could have a dialog for this, since it's geom settings it could use the same control as the layer options we have at the moment.

rdstern commented 6 years ago

Could we change Describe > Themes... to Describe > Defaults and then have 2 dialogues, one for Geoms and the other for Themes? Then could the dialogue for Geoms have simply a main dialogue with the Layer > Geom control. As the main control. I presume the R-code could then (at least start by being very simple, i.e. just the update_geom_defaults command?

If that is all we do, then it would mean that the default is updated for the current session. But it isn't saved and it isn't always obvious what the original default was. So undoing the setting isn't trivial. I suggest we live with both limitations for now.

This is partly in the interest of speed. But also because of the ggthemr package. This is currently not in CRAN, but it does seem to define a theme more broadly, as including new settings to a theme as also including the geom options. So that should solve the problems in the future.

For now I suggest we become pragmatic. I will usually need this feature when I prepare a set of consistent graphs for (say) PICSA. This will involve only 2 or 3 geom settings and would be simple with this new facility. And the limitations are not a great problem.

dannyparsons commented 6 years ago

I think we could easily reset to the standard defaults by unloading and reloading the ggplot2 package. That seemed to be suggested from what I read but haven't actually tried it.

rdstern commented 6 years ago

Sounds really good.