Two geom_points add a legend

前端 未结 4 1735
悲哀的现实
悲哀的现实 2020-11-29 06:45

I plot a 2 geom_point graph with the following code:

source(\"http://www.openintro.org/stat/data/arbuthnot.R\")
library(ggplot2)
ggplot() +
  geom_point(aes(         


        
4条回答
  •  借酒劲吻你
    2020-11-29 07:22

    This is the trick that I usually use. Add colour argument to the aes and use it as an indicator for the label names.

    ggplot() +
      geom_point(aes(x = year,y = boys, colour = 'Boys'),data=arbuthnot) +
      geom_point(aes(x = year,y = girls, colour = 'Girls'),data=arbuthnot,shape = 17) +
      xlab(label = 'Year') +
      ylab(label = 'Rate')
    

提交回复
热议问题