ggplot2数据分析与图形艺术书中代码,为什么我把aes写在前面会报错呢?
#原代码(书中代码)
library(ggplot2)
presidential <- subset(presidential,start>economics$date[1])
ggplot(economics)+
geom_rect(aes(xmin=start,xmax=end,fill=party),ymin=-Inf,ymax=Inf,alpha=0.2,data=presidential)+
geom_vline(aes(xintercept=as.numeric(start)),data=presidential,colour="grey50",alpha=0.5)+
geom_text(aes(x=start,y=2500,label=name),data=presidential,size=3,Vjust=0,hjust=0,nudge_x =50)+
geom_line(aes(date,unemploy))+
scale_fill_manual(values = c("blue","red"))
#我的想法
ggplot(economics,aes(date,unemploy))+
geom_line()+
geom_rect(aes(xmin=start,xmax=end,fill=party),ymin=-Inf,ymax=Inf,alpha=0.2,data=presidential)
Error in FUN(X[[i]], ...) : object 'unemploy' not found