Help with geom_abline legend

In the following reprex I want to keep the legend associated with geom_line and get rid of the legend associated with geom_point. Any suggestions gratefully accepted.

``` r
library(tidyverse)
t <- tibble(x =  c(1,2,3), y = c(3,1,2), s = c(1,2,3))
t |> ggplot(aes(x,y,size = s)) +
  geom_point(alpha = 0.3, color = "blue") +
  geom_abline(aes(color = "red", intercept = 1, slope = 1)) +
  geom_abline(aes(color = "green", intercept = 0,slope=.5))


Created on 2023-12-06 with reprex v2.0.2

Just add show.legend = FALSE:

t |> ggplot(aes(x,y,size = s)) +
  geom_point(alpha = 0.3, color = "blue", show.legend = FALSE) +
  geom_abline(aes(color = "red", intercept = 1, slope = 1)) +
  geom_abline(aes(color = "green", intercept = 0,slope=.5))
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.