ggforce icon indicating copy to clipboard operation
ggforce copied to clipboard

Feature request: add label_colour as an aesthetic

Open MattCowgill opened this issue 4 years ago • 5 comments

Hello, Thank you for a very useful package.

It would be handy to be able to map label.colour to the data as an aesthetic. As an example:

library(ggplot2)
library(ggforce)

ggplot(mtcars, aes(x = wt, y = mpg, col = factor(cyl))) +
  geom_point() +
  ggforce::geom_mark_ellipse(aes(label = cyl)) 

Created on 2021-06-11 by the reprex package (v2.0.0)

Here it would be useful to colour the 4, 6, and 8 labels the same as the points and ellipses, by mapping them to the data.

We can colour all annotations:

library(ggplot2)
library(ggforce)

ggplot(mtcars, aes(x = wt, y = mpg, col = factor(cyl))) +
  geom_point() +
  ggforce::geom_mark_ellipse(aes(label = cyl),
                             label.colour = "red") 

Created on 2021-06-11 by the reprex package (v2.0.0)

But label.colour is not implemented as an aesthetic:

library(ggplot2)
library(ggforce)

ggplot(mtcars, aes(x = wt, y = mpg, col = factor(cyl))) +
  geom_point() +
  ggforce::geom_mark_ellipse(aes(label = cyl,
                                 label.colour = cyl)) 
#> Warning: Ignoring unknown aesthetics: label.colour

Created on 2021-06-11 by the reprex package (v2.0.0)

Making label.colour an aesthetic would be a really useful addition to the package.

MattCowgill avatar Jun 11 '21 00:06 MattCowgill

I'm also looking for this...

rjake avatar Jun 11 '21 13:06 rjake

I agree this would be very handy to increase readability of all `geom_mark_*() functions when there are many categories or when they inconveniently overlap.

I think con.colour could similarly be made an aesthetic: I can see people preferring colouring the connector rather than the text of the label.

stragu avatar Jun 12 '22 14:06 stragu

It is unfortunately not as simple as it sounds, since label.colour (and con.colour) would need their own scales as well etc and it quickly becomes unwieldy.

How would people feel about a sentinel like 'inherit' that would indicate the colour coming from the main colour aesthetic? It is also not straightforward to make work, but is probably a better path to take

thomasp85 avatar Aug 31 '22 11:08 thomasp85

I think 'inherit' would be sufficient as I don't expect it would be particularly popular to colour the connectors and labels with a scale different to the ellipses'.

stragu avatar Aug 31 '22 15:08 stragu

I agree 'inherit' would do the job! Thank you @thomasp85

MattCowgill avatar Sep 01 '22 00:09 MattCowgill