corybrunson / ggalluvial

ggplot2 extension for alluvial plots
http://corybrunson.github.io/ggalluvial/
GNU General Public License v3.0
497 stars 34 forks source link

Explicit reference to alpha value added to colour/colors and ability to edit it #112

Closed SimonDedman closed 1 year ago

SimonDedman commented 1 year ago

Hi Cory, It seems ggalluvial adds an unspecified alpha amount to colours used in (e.g.) scale_fill_manual, with no obvious way to edit that. I understand this is in order to highlight where flows overlap, but it would be nice to be able to play with that alpha value in order to produce stronger-coloured plots.

Thanks!

corybrunson commented 1 year ago

Hi @SimonDedman, i think i know what you're asking. Please have a look at the second example here. Does it illustrate what you want to do?

SimonDedman commented 1 year ago

It does yeah, thanks mate. Would it be possible to mention that in the docs for geom_alluvium, maybe even pull it out from the ... layer implicit call and make alpha = 1/2 an explicit call since it's a changed default?

corybrunson commented 1 year ago

On the first part, i don't think the {ggalluvial} documentation is the right place for guidance on how to use aesthetic specifications, at least in detail; it imports and adapts the API from {ggplot2}, where this is explained here, for example. Though i don't think the {ggalluvial} documentation explicitly states that users should consult the {ggplot2} documentation for general questions about the API and internals. Maybe it should?

I'm not sure what you mean by pulling the alpha parameter out. Where in the code are you looking? Probably it's best left where it is; i try to adhere to the standards and conventions of {ggplot2} extensions. I will definitely make a change if i've failed to do that.

SimonDedman commented 1 year ago

Thanks for the reply. What I mean by pulling it out is: currently as I understand it you're applying an alpha = 0.5 call to ggplot / layer (apologies, a bit rusty on this now), but this is hidden from the users. They just notice (or not) that the colours they ask for, aren't provided. IMO if you're changing the defaults of how ggplot works, you should include this as an explicit parameter in geom_alluvium, which will be passed down to ggplot/layer. Other things can be passed by the user downwards, but if geom_alluvium doesn't change the defaults, they don't need to be specified.

As it stands, the user can enter a colour scheme and not get it, and have no way of working out why unless they crack open your functions one by one until they find a reference to alpha, which is a real drag. They should be able to look at the help file, ideally for the function they're using (geom_alluvium), and see the alpha value has been applied, and thus they can change it.

corybrunson commented 1 year ago

OK, i think i see the issue: To my knowledge, {ggplot2} doesn't have any package-wide default aesthetic values. Rather, each geom plot layer has its own defaults, and these vary from layer to layer. For example, different geoms in {ggplot2} itself have different default values for colour, size, and linewidth. These defaults are selected to produce the most natural or useful behavior. Because the flows in alluvial plots overlap each other, an alpha value other than 0 or 1 is desirable, so that all flows are visible. Choosing 0.5 specifically was somewhat arbitrary, but it seems to work well in practice.

I see that the {ggplot2} documentation for geom layers does now link to the vignette i linked to above. (See, for example, geom_polygon(), which has a line "Learn more about setting these aesthetics" directly under the aesthetics list.) I'll make a point to add a similar line to the documentation in {ggalluvial}. Would that address your concern about users being able to figure out how to change aesthetic specifications directly from the geom_alluvium() documentation?

SimonDedman commented 1 year ago

I think so, presuming you mention that geom_alluvium() sets a default alpha of 0.5 so you explicitly tell the users this. Cheers!