laresbernardo / lares

Analytics & Machine Learning R Sidekick
https://laresbernardo.github.io/lares/
233 stars 49 forks source link

Customising (applying limits to fill scale for) corr_cross #44

Closed NikitaEGroot closed 1 year ago

NikitaEGroot commented 1 year ago

Hello, hope it's okay for me to ask for help here, otherwise happy to take it down and ask in the right place - it is probably less of an issue so much as me not yet understanding all the functions taking place "under the hood" of corr_cross. I'm still fiddling with aesthetics and I can't seem to get my plots to be consistent - I have a two-colour scale I'd like to use to split positive and negative correlations, but if no negative correlations are returned my positive correlations are given the fill usually given to the negative ones. I know it's a bit of a silly problem!

I've tried adding a limits argument to scale_fillmanual, which returns: "Warning message: Continuous limits supplied to discrete scale.ℹ Did you mean limits = factor(...) or `scale*_continuous()`? "

I tried the suggested limits=factor(-1, 1), which produced a plot that looked the same as without any limits argument.

I've tried using scale_fill_gradient / scale_fill_continuous, which returns: Error: Discrete value supplied to continuous scale

Which has very much confused me, because it looks like the fill values are Schrödinger-style discrete and continuous?

laresbernardo commented 1 year ago

Hi! This seems more of an issue trying to customize the ggplot object rather than using the library. Re the corr_cross() function, we apply theme_lares() by default to our plots so that all plot outputs have a consistent colour palette and theme. That said, once you have your object, you can customize the ggplot object to follow your style needs.

NikitaEGroot commented 1 year ago

Hi, thanks for your response!

I found a solution which I'll just share here in case anyone else wants to fiddle around with colours like I do - it ended up being really simple to just use the following (from https://rdrr.io/github/laresbernardo/lares/man/gg_fill_customs.html):

options("lares.colours.custom" = data.frame(
  values = c("positive", "negative"),
  fill = c("postivecolourthatIwanted", "negativecolourthatIwanted"),
  colour = c("black", "white")
))

With of course editing the the fill argument with whatever hex codes I desired. This had the added bonus of not producing any warnings like “Scale for ‘fill’ is already present. Adding another scale for ‘fill’, which will replace the existing scale.” You can do this for pretty much any colour in the theme depending on how that colour is retrieved - for corr_cross() I only needed positive and negative, but you can access the full list for true/false, different social media or the full palette etc with lares_pal(), all of which can be edited with variations of the code above.

Many thanks for building in these options for customisation!

laresbernardo commented 1 year ago

That’s exactly right! That’s the easiest way to customize the palette. Actually I had forgot about that option since it always uses the palette I set by default for me and I enabled that option for other users to personalize! Thanks for sharing.