ggeasy icon indicating copy to clipboard operation
ggeasy copied to clipboard

Labellers

Open AliciaSchep opened this issue 7 years ago • 2 comments

I just recently discovered some of the useful labelling functions in ggplot for labelling facets, e.g. "label_both" and "label_wrap_gen". I think it could be nice to have some additional labellers.

?as_labeller brings up some nice examples of a few labellers:

p <- ggplot(mtcars, aes(disp, drat)) + geom_point()
p + facet_wrap(~am)

# Rename labels on the fly with a lookup character vector
to_string <- as_labeller(c(`0` = "Zero", `1` = "One"))
p + facet_wrap(~am, labeller = to_string)

# Quickly transform a function operating on character vectors to a
# labeller function:
appender <- function(string, suffix = "-foo") paste0(string, suffix)
p + facet_wrap(~am, labeller = as_labeller(appender))

Both the to_string and appender (and prepender) could be nice (with to_string made into more general function that takes integers and converts to the word).

Another type of labeller I think would be useful would be something that takes snake_case or period.case into separate words. I find that I often use gather before ggplot and then end up with a column where the variables are in snake_case because the column name were snake_case. While that fix can happen in that data pre-processing, it could also be nice as a labeller if you only care about the transformation in context of plotting.

AliciaSchep avatar Nov 10 '17 03:11 AliciaSchep

I like this, but I'm cautious about how far we venture away from 'helpers to make existing calls easier' into 'look what else you can do'. I can see something like easy_facet_with_labels(formula, named_string) which resolves to facet_wrap(~formula, labeller = as_labelller(named_string)) fitting nicely within this package.

I could also see a easy_facet_with_titles() if the intermediate code isn't too complicated.

jonocarroll avatar Nov 12 '17 21:11 jonocarroll

Yeah, I can see that having a ton of new labellers might be out-of-scope for this package. Actually was thinking of creating a new issue for clarifying scope question -- think it would be good to add a CONTRIBUTING file that has guidelines for contributing and also touches on intended scope.

I like the easy_facet_with_labels idea. For easy_facet_with_titles() was the idea that this would be the cleaning up of names I mentioned at end? Code wouldn't be very complicated for that, just a bit of regex.

AliciaSchep avatar Nov 13 '17 06:11 AliciaSchep