R ggplot2错误“;“绘图中没有图层”;

R ggplot2错误“;“绘图中没有图层”;,r,ggplot2,R,Ggplot2,我已经看到了已经提出的问题。。。并解决了将stat=“identity”添加到geom\u栏中的问题。 但在我的例子中,这并不能解决任何问题(我仍然得到消息“绘图中没有图层”) 我得到了一个简单的data.frame(data3),包含2个因子(MonthNB和StationNAME)和一个数值变量(Ptot): 我尝试使用以下方法绘制Ptot=f(MonthNB): d错误消息是因为您没有将d+geom_line()保存为对象 #Save ggplot() as object d <-

我已经看到了已经提出的问题。。。并解决了将
stat=“identity”
添加到
geom\u栏中的问题。
但在我的例子中,这并不能解决任何问题(我仍然得到消息“绘图中没有图层”)

我得到了一个简单的data.frame(data3),包含2个因子(MonthNB和StationNAME)和一个数值变量(Ptot):

我尝试使用以下方法绘制Ptot=f(MonthNB):


d错误消息是因为您没有将
d+geom_line()
保存为对象

#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()
#将ggplot()另存为对象

d错误是因为没有添加geom_line()或geom_point()选项。添加此选项时,可以直接打印,而无需将其另存为对象

d <- ggplot(data=data3, aes(x=MonthNB, y=Ptot, colour=StationNAME))
d + geom_line()
d
#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()
d<-d+geom_line()
#No error message
d