Closed adamblake closed 2 years ago
This looks like it will be pretty easy to do. My plan is to create two new functions: use_ggformula_defaults()
and revert_ggformula_defaults()
. The former will be called when the package loads so the change won't be noticeable for most users. revert_ggformula_defaults()
currently has hard-coded defaults from ggplot2
, so it isn't a proper reversion if other things have been done.
One note: You can't actually set the defaults for histograms since there is no histogram geom or stat. Instead geom_histogram()
is a wrapper around a call to layer()
with StatBin
and GeomBar
. So the defaults need to be set for GeomBar
and will affect any plot that uses bars, not just histograms. That probably isn't a problem, but it will be a small change in behavior.
suppressPackageStartupMessages(library(ggformula))
revert_ggformula_defaults()
gf_histogram(~rnorm(100), color = "black")
use_ggformula_defaults()
gf_histogram(~rnorm(100), color = "black")
Created on 2022-07-18 by the reprex package (v2.0.1)
While I'm at it, I think I'll set the ggformula
default fill to NA for boxplots. Students often have issues layering boxplots because of the ggplot2's default opaque fill.
suppressPackageStartupMessages(library(ggformula))
revert_ggformula_defaults()
mosaicData::HELPrct |>
gf_sina(age ~ substance) |>
gf_boxplot()
use_ggformula_defaults()
mosaicData::HELPrct |>
gf_sina(age ~ substance) |>
gf_boxplot()
Created on 2022-07-18 by the reprex package (v2.0.1)
Demo of alpha for boxplots:
suppressPackageStartupMessages(library(ggformula))
revert_ggformula_defaults()
mosaicData::HELPrct |>
gf_sina(age ~ substance, color = ~ substance, fill = ~ substance) |>
gf_boxplot()
use_ggformula_defaults()
mosaicData::HELPrct |>
gf_sina(age ~ substance, color = ~ substance, fill = ~ substance) |>
gf_boxplot()
Created on 2022-07-18 by the reprex package (v2.0.1)
This looks fantastic @rpruim
@adamblake , this should be heading to CRAN soon. {mosaic} and {mosaicCalc} were updated last week, so now I'm ready to do the testing and other prep to get this package onto CRAN.
Looking forward to trying it out! Thanks!
Hi, love this package, we use it extensively over at CourseKata.org. Lately, we have been working on a CourseKata theme for
ggplot2
plots (andggformula
, naturally) and the way we set defaults for geoms is to useggplot2::update_geom_defaults()
(we have some functions calledload_coursekata_themes()
andrestore_default_themes()
that update the defaults).Using this method, we can set up colorblind and contrast-friendly colors for all of our plots. This works for every geom except the histograms and density plots when we run them through
ggformula
. It appears that this is because you set the default transparency as a default for thealpha
parameter in the function signature. When we try to update the geom defaults (we prefer the more opaque .7), youralpha
parameter overrides our defaults to .5Would you consider changing the way you set this default, or possibly remove it? It seems somewhat out-of-place to have this set in this package as the rest of the package seems to mostly just wrap
ggplot2
, but maybe I have misinterpreted something.Thanks for your consideration!