ggplot2 legend for abline and stat_smooth

前端 未结 3 793
生来不讨喜
生来不讨喜 2021-01-13 13:32

I have some problems with ggplot legends, here is my first code with only the legend for corrGenes, which is fine.

gene1=c(1.041,0.699,0.602,0.602,2.585,0.60         


        
3条回答
  •  情书的邮戳
    2021-01-13 14:13

    Not sure if this is the best solution, but I was able to tell ggplot to have two scales, one for the colours (your points), the other one for the fill colour. Which fill colour you are probably asking? The one I added in the aes for the two lines:

    plot = ggplot(data=DF,aes(x=gene1,y=BIME)) + 
      geom_point(size=5, aes(colour=corrGenes)) +
      geom_abline(aes(fill="black"),intercept=0, slope=1) + 
      stat_smooth(aes(fill="blue"), method = "lm",se=FALSE) +
      scale_fill_manual(name='My Lines', values=c("black", "blue"))+
      ylab("BIME normalized counts (log10(RPKM))")+
      xlab("gene1 normalized counts (log10(RPKM))")
    

    enter image description here

提交回复
热议问题