Adding an extra item to the legend

前端 未结 1 485
抹茶落季
抹茶落季 2021-01-22 21:21

I have the following data:

trait,beta,se,p,analysis,signif
trait1,0.078,0.01,9.00E-13,group1,1
trait2,0.076,0.01,1.70E-11,group1,1
trait3,-0.032,0.01,0.004,group         


        
相关标签:
1条回答
  • 2021-01-22 21:52

    Add dummy aes() to geom_point - for example fill that is named significant aes(fill = "Significant").

    # Using OPs data
    library(ggplot2)
    ggplot(GEE, aes(y=beta, x=reorder(trait, beta), group=analysis)) + 
      geom_point(data = GEE[GEE$signif == 1, ],
                 color="red",
                 shape = "*", 
                 size=12,
                 aes(fill = "Significant")) +
      geom_point(aes(color=analysis)) +
      geom_errorbar(aes(ymin=beta-2*se, ymax=beta+2*se,color=analysis), width=.2,
                    position=position_dodge(.2)) +
      geom_hline(yintercept = 0) +
      theme_light() +
      theme(axis.title.y=element_blank(),
            legend.title=element_blank()) +
      coord_flip() +
      guides(colour = guide_legend(order = 1), 
             fill = guide_legend(override.aes = list(size = 5))) +
      theme(legend.margin = margin(-0.5,0,0,0, unit="cm"))
    

    PS: I also removed show.legend = F from asterik geom_point

    0 讨论(0)
提交回复
热议问题