本文介绍了ggplot2错误“绘图中没有图层”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我已经看到了已经问过的问题,并且解决了将 stat =identity添加到 geom_bar 。 但在我的情况下,这并没有解决任何问题(我仍然收到无图层的信息消息)。 我有一个简单的data.frame (数据3)与2个因素(MonthNB和StationNAME)和一个数值变量(Ptot): MonthNB StationNAME Ptot 1站A 21.70625 2站A 16.19375 3站A 16.64688 4站A 27.37813 5站A 38.26774 6站A 52.91250 7站A 69.36875 8 A站43.18125 9站A 33.24688 10站A 35.74839 11站A 36.01333 12站A 30.24194 1站B 25.14242 2站B 18.62121 3站B 22.11818 4站B 32.70909 5站B 33.83750 6站B 63.65937 7站B 69.05312 8站B 50.70606 9站B 46.96364 10站B 50.28710 11 stationB 46.81935 12 stationB 39.88750 我试图绘制Ptot = f (MonthNB)使用: d d + geom_line()d 解决方案 div> 错误信息是由于您没有将 d + geom_line()保存为对象。 #将ggplot()保存为对象d #添加到geom_line() - 这会使图表出现在屏幕上,但不会保存。 d + geom_line() 将图层保存到对象中 d #无错误信息d 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 get the message "no layers in plot").I got a simple data.frame (data3) with 2 factors (MonthNB and StationNAME) and one numerical variable (Ptot): MonthNB StationNAME Ptot 1 stationA 21.70625 2 stationA 16.19375 3 stationA 16.64688 4 stationA 27.37813 5 stationA 38.26774 6 stationA 52.91250 7 stationA 69.36875 8 stationA 43.18125 9 stationA 33.24688 10 stationA 35.74839 11 stationA 36.01333 12 stationA 30.24194 1 stationB 25.14242 2 stationB 18.62121 3 stationB 22.11818 4 stationB 32.70909 5 stationB 33.83750 6 stationB 63.65937 7 stationB 69.05312 8 stationB 50.70606 9 stationB 46.96364 10 stationB 50.28710 11 stationB 46.81935 12 stationB 39.88750I tried to plot Ptot=f(MonthNB) using:d <- ggplot(data=data3, aes(x=MonthNB, y=Ptot, colour=StationNAME))d + geom_line()d 解决方案 The error message is due to fact that you didn't save d+geom_line() as an object.#Save ggplot() as objectd <- 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 objectd<-d+geom_line()#No error messaged 这篇关于ggplot2错误“绘图中没有图层”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-05 20:41