Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Geom_point : when using color and alpha : how to delete the alpha legend in ggplot?

I have this df that is visalised as followed

df = data.frame(x = -10:11,
                y = seq(-5,5.5,by=0.5),
                z = rep(c(1,2),11) )

df

ggplot(df)+aes(x=x,y=y,color=factor(z),alpha=z)+
  geom_point()+
  geom_hline(yintercept=0)+
  geom_vline(xintercept = 0)+
  theme_blank()

The output
enter image description here

I checked all similar questions but nothing has worked out to remove the alpha legend. Thanks.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could add in alpha in aesthetics and use guides to remove it like this:

df = data.frame(x = -10:11,
                y = seq(-5,5.5,by=0.5),
                z = rep(c(1,2),11) )
library(ggplot2)

ggplot(df)+aes(x=x,y=y,color=factor(z), alpha=z)+
  geom_point()+
  geom_hline(yintercept=0)+
  geom_vline(xintercept = 0) +
  guides(alpha = "none")

Created on 2023-01-20 with reprex v2.0.2

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading