0
$\begingroup$

I have a count plot in R with 3 different values on the legend (1000, 2000, 3000). What I want to do is to color them in such a way, that the color of every next value is more intense. So 1000 would be very pale and 3000 would be very intense. I don't know whether it's a case of alpha or coloring, I'm pretty new to R overall. However I couldn't find any insight in the documentation. I'm using geom_count in ggplot2 for the plot.

What I have now: what i have

What I want: what i want

Any help would be very appreciated!

$\endgroup$
2
  • $\begingroup$ Can you share the code you are currently using to create the plot? If I remember correctly you can use the color keyword in ggplot to color the points based on a value. $\endgroup$
    – Oxbowerce
    Dec 19, 2021 at 14:41
  • $\begingroup$ Sure. That's what I'm using: ggplot(data, aes(x, y)) + geom_count(alpha=0.5, color="blue") $\endgroup$
    – 7ired
    Dec 19, 2021 at 15:16

1 Answer 1

2
$\begingroup$

You can simply use the color keyword in the aes function to refer to the variable based on which you want to color your points (see also this answer on stackoverflow):

ggplot(data, aes(x, y)) + geom_count(aes(color=..n..), alpha=0.5) 
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.