ggplot legend not working with scale_colour_manual

前端 未结 1 1211
余生分开走
余生分开走 2021-01-13 00:24

I know an identical question has been asked earlier. ggplot legend - scale_colour_manual not working

But the question involves a somewhat complicated dataset than wh

相关标签:
1条回答
  • 2021-01-13 01:26

    You have to use show_guide=TRUE in geom_vline (defaults to FALSE):

    p <- data.frame(a = runif(10, 1, 2))
    ggplot(data=p, aes(x=a)) +
      geom_histogram() +
      geom_vline(aes(xintercept=mean(a), colour="mea"), show_guide=TRUE) +
      geom_vline(aes(xintercept=median(a), colour="med"), show_guide=TRUE) +
      scale_colour_manual(name="Statistic",
                          values=c("med"= "red", "mea"="green"))
    

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