Additional legend in ggplot2

前端 未结 1 1732
萌比男神i
萌比男神i 2021-01-26 06:28

I have a problem where the legend of my ggplot() does not appear. Here\'s my code:

plot_bt <- ggplot(NULL, aes(x, v1)) + 
  geom_line(data = nig_         


        
1条回答
  •  旧时难觅i
    2021-01-26 07:30

    Just do this:

    plot_bt <- ggplot(NULL, aes(x, v1)) + 
      geom_line(data = nig_bt_1, aes(colour = "a")) +
      geom_line(data = nig_bt_2, aes(colour = "b")) +
      geom_line(data = nig_bt_3, aes(colour = "c")) + 
      labs(x = "X", y = "Probability") +
      scales_color_manual(values= c("a" = "black", "b" = "blue", "c" = "red"))
    

    A guide can only depict mappings you've defined using aes. The ggplot2 way is of course to first combine the data and use a grouping variable.

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