How to deal with “data of class uneval” error from ggplot2?

前端 未结 3 748
生来不讨喜
生来不讨喜 2020-11-30 23:37

While trying to overlay a new line to a existing ggplot I am getting the following error:

Error: ggplot2 doesn\'t know how to deal with data of class uneval         


        
3条回答
  •  爱一瞬间的悲伤
    2020-12-01 00:28

    Another cause is accidentally putting the data=... inside the aes(...) instead of outside:

    RIGHT:
    ggplot(data=df[df$var7=='9-06',], aes(x=lifetime,y=rep_rate,group=mdcp,color=mdcp) ...)
    
    WRONG:
    ggplot(aes(data=df[df$var7=='9-06',],x=lifetime,y=rep_rate,group=mdcp,color=mdcp) ...)
    

    In particular this can happen when you prototype your plot command with qplot(), which doesn't use an explicit aes(), then edit/copy-and-paste it into a ggplot()

    qplot(data=..., x=...,y=..., ...)
    
    ggplot(data=..., aes(x=...,y=...,...))
    

    It's a pity ggplot's error message isn't Missing 'data' argument! instead of this cryptic nonsense, because that's what this message often means.

提交回复
热议问题