ggplot2书中有一处代码:
p<-ggplot(diamonds,aes(carat,price,colour=cut))
p<-p+layer(geom=“point”)
错误: Attempted to create layer with no stat.
Runrlang::last_error()
to see where the error occurred.
错误原因:
attempted to create layer with no stat. 试图创建没有属性的层
解决方案:
加入属性stat
p<-ggplot(diamonds,aes(carat,price,colour=cut))
p<-p+layer(geom="point",stat="identity",position="identity")
当然我们也可以简化上边的代码:
```r
p<-ggplot(data=diamonds,mapping=aes(carat,price,colour=cut),stat="identity",position="identity")+geom_point()
p