ggplot2 error “no layers in plot”

前端 未结 2 760

I have seen the question already asked... and solved adding stat = \"identity\" to geom_bar. But in my case, this does not solve anything (I still

2条回答
  •  爱一瞬间的悲伤
    2020-12-15 19:44

    The error message is due to fact that you didn't save d+geom_line() as an object.

    #Save ggplot() as object
    d <- ggplot(data=data3, aes(x=MonthNB, y=Ptot, colour=StationNAME))
    
    #Add to d geom_line() - this makes the plot to appear on the screen but not saved.
    d + geom_line()
    

    To save layer to object

    d<-d+geom_line()
    #No error message
    d
    

提交回复
热议问题