ggplot2 Legend matching linetype

Hi, this is my first code in R for a work at university. I plotted a graph with ggplot, but i cant figure out why the Legend is not matching with the linetypes. I tried different things from other online questions. But i think because i am so new to this topic i need some more help. Hopefully someone can help me and explain my Problem. I would like to upload a picture of the plot, but iam not allowed.

ggplot(Statv, aes(x= (180:280), y= Statv[,2], color = "KS Statistic"),
lty="solid")+
labs(y= "KS Statistic", x="M Value", colour = "Legend")+
theme_bw()+
geom_line()+
geom_line(aes(y= CriticalV1, color="Critical Value for alpha = 0.1"),
lty="solid")+
geom_line(aes(y= CriticalV2, color="Critical Value for alpha = 0.2"),
lty= "dashed")+
scale_y_continuous(limits = (c(0.04,0.19)),
breaks = seq(0.04,0.19,0.02))+
scale_colour_manual(values = c("KS Statistic"= "black",
"Critical Value for alpha = 0.1" = "red",
"Critical Value for alpha = 0.2" = "red2"))+
scale_linetype_manual(values = c("KS Statistic"= 1,
"Critical Value for alpha = 0.1" =1 ,
"Critical Value for alpha = 0.2" =2))+
theme(legend.position = c(0.27,0.15),
legend.background = element_blank(),
legend.title = element_blank())

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

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