0

I have mapped the Sex variable into the scatterplot, and GGPlot automatically gives me a legend for Sex, but I can't add the abline to the legend no matter what I try. I need to mark the black line as abline in the legend.

library(tidyverse)

ggplot(y_ela_test.total_sex, aes(x=Age, y=s0, color=Sex, shape=Sex)) + geom_point() + geom_smooth(method=lm,aes(color = Sex, fill = Sex))+theme(plot.title = element_text(hjust = 0.5, vjust=4, size = 10))+geom_abline(color="black",linetype="dashed",size=1)

enter image description here I output like this.

But I need to mark the black line as abline in the legend.

the dataset like this.

enter image description here

  • 1
    It would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data. – stefan Jul 25 '22 at 19:59
  • ggplot(y_ela_test.total_sex, aes(x=Age, y=s0, color=Sex, shape=Sex)) + geom_point() + geom_smooth(method=lm,aes(color = Sex, fill = Sex))+theme(plot.title = element_text(hjust = 0.5, vjust=4, size = 10))+geom_abline(color="black",linetype="dashed",size=1) – user19254514 Jul 25 '22 at 20:20

0 Answers0