Error: stat_smooth requires the following missing aesthetics

Published by onesixx on

geom_smooth(stat_smooth)에 상속된 aes()가 잘못됐을 경우 발생 

http://stulp.gmw.rug.nl/ggplotworkshop/twocontinuousvariables.html  ::  12.1.1.1 inherite.aes
### 동력전달타입(drv)별 배기량(displ)이 도심 주행연비(cty)에 미치는 영향

p <- mpg %>% ggplot(aes(displ, cty, color=drv)) 

p + geom_point() + 
    geom_smooth(method="lm", se=F, inherit.aes=F)
# Error: stat_smooth requires the following missing aesthetics: x, y


p + geom_point() + 
    geom_smooth(method="lm", se=F)

###  same above ----
p + geom_point(inherit.aes=T) + 
    geom_smooth(method="lm", se=F, , inherit.aes=T)

p + geom_point( data=mpg, aes(x=displ, y=cty, colour=drv)) + 
    geom_smooth(data=mpg, aes(x=displ, y=cty, colour=drv), method="lm", se=F)

p + geom_point( aes(x=displ, y=cty, colour=drv)) + 
    geom_smooth(aes(x=displ, y=cty, colour=drv), method="lm", se=F)

mpg %>% ggplot() + 
  geom_point( aes(x=displ, y=cty, colour=drv)) + 
  geom_smooth(aes(x=displ, y=cty, colour=drv), method="lm", se=F)

ggplot() + 
  geom_point( data=mpg, aes(x=displ, y=cty, colour=drv)) + 
  geom_smooth(data=mpg, aes(x=displ, y=cty, colour=drv), method="lm", se=F)
### --- --- --- --- ---


p + geom_point(inherit.aes=T) + 
    geom_smooth(aes(x=displ, y=cty, colour=drv), method="lm", se=F, inherit.aes=F)

p + geom_point(inherit.aes=T) + 
    geom_smooth(aes(x=displ, y=cty), method="lm", se=F, inherit.aes=F)

p + geom_point() + 
    geom_smooth(method="lm", se=F) +
    geom_smooth(aes(x=displ, y=cty), method="lm", se=F, inherit.aes=F, colour="black", size=1, linetype="dashed")
Categories: R ggplot2

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x