Home > Net >  Suppress elements from legend
Suppress elements from legend

Time:09-30

i have following Chart:

Author_csv %>%
    ggplot(aes(x=X, y=Y))  
      geom_jitter(aes(color=Autor), show.legend = F)  
      geom_segment(aes(x = 0, xend = 7, y = 0, yend = 3.5, colour = "dashed"), linetype="dashed", size=0.3)  
      geom_segment(aes(x = 0, xend = 7, y = 7, yend = 3.5, colour = "dashed"), linetype="dashed", size=0.3)  
      geom_segment(aes(x = 0, xend = 7, y = 0, yend = 7, colour = "solid"), linetype="solid", size=0.3)

resulting in this graph: Graph

I want to suppress the Jitter from the Legend. I only want to see my geom segment Lines with the label dashed/solid. How would i do this?

CodePudding user response:

Instead of

geom_jitter(aes(color=Autor), show.legend = F)

Try using

geom_jitter(aes(fill=Autor), shape = 21, colour = "transparent", show.legend = FALSE)

Here is an example using the palmerpenguins dataset:

library(tidyverse)
library(palmerpenguins)

penguins %>% 
  na.omit() %>%
ggplot(aes(x=species, y=bill_length_mm))  
  geom_jitter(aes(fill=island), shape = 21, colour = "transparent", show.legend = FALSE)  
  geom_segment(aes(x = 0, xend = 3.5, y = 0, yend = 35, colour = "dashed"), linetype="dashed", size=0.3)  
  geom_segment(aes(x = 0, xend = 3.5, y = 70, yend = 35, colour = "dashed"), linetype="dashed", size=0.3)  
  geom_segment(aes(x = 0, xend = 3.5, y = 0, yend = 70, colour = "solid"), linetype="solid", size=0.3)

Created on 2021-09-23 by the reprex package (v2.0.1)

  • Related