0

I have to make a plot with multiple variables. All woks well exept my legend. The shape for each of the three variables are overlapping on each other in the legend. Here is my code :

colors <- c("Satr" = "blue", "Thth" = "red", "Abbr" = "darkgreen")

ggplot(data = Database, mapping =  aes( x = Station,)) +
  geom_point(aes(, y =  Satr, color = "Satr"), size = 3,shape=0) + 
  geom_point(aes(, y =  Thth, color = "Thth"), size = 3, shape=19) + 
  geom_point(aes(, y =  Abbr, color = "Abbr"), size = 3.5, shape=5) +
  theme_bw() +
  scale_x_continuous(breaks=seq(0, 30, by = 1)) +
  ggtitle(label = "Presence of the brown trout (Satr), grayling (Thth) and common bream (Abbr) 
          in the different stations of the Doubs river") +
  theme(plot.title = element_text(hjust = 0.5)) +
  ylab(label = "fish abundance" ) +
  xlab(label = "Stations" ) +
  labs(color = "Legend")+
  scale_color_manual(values = colors)
  

I try to use scale_shapes_manual() but it didn't work.

Phil
  • 7,287
  • 3
  • 36
  • 66
  • 1
    Instead of using multiple `geom_point()` calls, you need to pivot your data into long format. See https://stackoverflow.com/a/10349375/5221626 – Phil Jun 21 '23 at 20:47
  • Second option: Similar to `color` map on the `shape` aes, e.g. do `aes(..., shape = "Satr")`, set your shapes via `scale_shape_manual` and add `labs(..., shape = "Legend")` to merge the legends. – stefan Jun 21 '23 at 21:04
  • 1
    Thanks ! The second worked ! – Romain Bernard Jun 21 '23 at 21:17

0 Answers0