Legend in ggplot2, remove level

后端 未结 1 1886
故里飘歌
故里飘歌 2021-01-22 05:09

My data:

df <- data.frame(sp = c(LETTERS[1:8]),
                 tr = c(\"NS\", \"LS\", \"NS\", \"LS\", \"LS\", \"HS\", \"HS\", \"HS\"),
                 bv =         


        
1条回答
  •  星月不相逢
    2021-01-22 05:22

    You can remove the variable legend by setting fill = FALSE in guides and you change the backgroundcolor with override.aes in guide_legend (also inside guides) as follows:

    ggplot(df1, aes(sp, value, fill = variable)) + 
      geom_bar(aes(lty = tr), lwd = 1.2, stat = "identity", colour = "black", width =.8) + 
      scale_linetype_discrete(name = "ja") +
      guides(fill = FALSE,
             lty = guide_legend(override.aes = list(lty = c('dotted', 'dashed', 'solid'),
                                                    fill = "white"))) +
      theme_classic() +
      theme(legend.position = "bottom")
    

    this results in the following plot:

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