r - latest version of ggplot2 creating issue with aes argument -
i had created custom function plot regression diagnostics these version of ggplot2 & gridextra under:
ggplot2 * 1.0.1 2015-03-17 cran (r 3.2.1) gridextra * 2.0.0 2015-07-14 cran (r 3.2.1) head(dadhospital) sl. body.weight total.cost.to.hospital ## 1 1 49 660293 ## 2 2 41 809130 ## 3 3 47 362231 ## 4 4 80 629990 ## 5 5 58 444876 ## 6 6 45 372357 fit1<-lm(total.cost.to.hospital~body.weight,data=dadhospital) #custom function of plotting model diagnostics using ggplot2 library(ggplot2) diagplot<-function(model){ p1<-ggplot(model, aes(.fitted, .resid))+geom_point() p1<-p1+stat_smooth(method="loess")+geom_hline(yintercept=0, col="red", linetype="dashed") p1<-p1+xlab("fitted values")+ylab("residuals") p1<-p1+ggtitle("residual vs fitted plot")+theme_bw() p2<-ggplot(model, aes(qqnorm(.stdresid)[[1]], .stdresid))+geom_point(na.rm = true) p2<-p2+geom_abline(aes(qqline(.stdresid)))+xlab("theoretical quantiles")+ylab("standardized residuals") p2<-p2+ggtitle("normal q-q")+theme_bw() p3<-ggplot(model, aes(.fitted, sqrt(abs(.stdresid))))+geom_point(na.rm=true) p3<-p3+stat_smooth(method="loess", na.rm = true)+xlab("fitted value") p3<-p3+ylab(expression(sqrt("|standardized residuals|"))) p3<-p3+ggtitle("scale-location")+theme_bw() p4<-ggplot(model, aes(seq_along(.cooksd), .cooksd))+geom_bar(stat="identity", position="identity") p4<-p4+xlab("obs. number")+ylab("cook's distance") p4<-p4+ggtitle("cook's distance")+theme_bw() p5<-ggplot(model, aes(.hat, .stdresid))+geom_point(aes(size=.cooksd), na.rm=true) p5<-p5+stat_smooth(method="loess", na.rm=true) p5<-p5+xlab("leverage")+ylab("standardized residuals") p5<-p5+ggtitle("residual vs leverage plot") p5<-p5+scale_size_continuous("cook's distance", range=c(1,5)) p5<-p5+theme_bw()+theme(legend.position="bottom") p6<-ggplot(model, aes(.hat, .cooksd))+geom_point(na.rm=true)+stat_smooth(method="loess", na.rm=true) p6<-p6+xlab("leverage hii")+ylab("cook's distance") p6<-p6+ggtitle("cook's dist vs leverage hii/(1-hii)") p6<-p6+geom_abline(slope=seq(0,3,0.5), color="gray", linetype="dashed") p6<-p6+theme_bw() return(list(rvfplot=p1, qqplot=p2, scllocplot=p3, cdplot=p4, rvlevplot=p5, cvlplot=p6)) } par(mfrow=c(1,1)) diagplts<-diagplot(fit1) #to display plots in grid, packages mentioned above should installed. library(gridextra) grid.arrange(diagplts$rvfplot,diagplts$qqplot,diagplts$scllocplot,diagplts$cdplot,diagplts$rvlevplot,diagplts$cvlplot,ncol=3)
now latest version of ggplot2
2.0.0
if run same function error:
error: aesthetics must either length 1 or same data (248): x
i need help. assume latest ggplot2
version, changes have been introduced aes
argument, not aware.
while debugging error here.... p2<-ggplot(fit1, aes(qqnorm(.stdresid)[[1]], .stdresid))+geom_point(na.rm = true) p2<-p2+geom_abline(aes(qqline(.stdresid)))+xlab("theoretical quantiles")+ylab("standardized residuals") p2<-p2+ggtitle("normal q-q")+theme_bw() p2 error: aesthetics must either length 1 or same data (248): x
you can replace code p2
withe special geom_qq()
makes same plot.
p2<-ggplot(model,aes(sample=.stdresid))+geom_qq() p2<-geom_abline()+xlab("theoretical quantiles")+ylab("standardized residuals") p2<-p2+ggtitle("normal q-q")+theme_bw()
for existing code need remove aes()
part geom_abline()
.
p2<-ggplot(model, aes(qqnorm(.stdresid)[[1]], .stdresid))+geom_point(na.rm = true) p2<-p2+geom_abline()+xlab("theoretical quantiles")+ylab("standardized residuals") p2<-p2+ggtitle("normal q-q")+theme_bw()
Comments
Post a Comment