
上QQ阅读APP看书,第一时间看更新
Visual plotting of the variables
Sometimes you may want to generate plots for all of the variables layed out in a matrix. While there are many packages available which will do this automatically, you can also do this yourself in code, as I have shown below. I have also limited to bar plots in which the number of levels are less than or equal to 20. I might want to look at the others later, and possibly condense some of the categories, however this shows me enough variables to get started:
colors = c("blue","green3","orange")
numcols <- length(names(df))
par(mfrow=c(3,5))
for(i in 1:numcols){
if(is.factor(df[,i])){
if( as.integer(nlevels(df[,i]) <= 20) ) plot(df[,i],main=names(df)[i],col=colors)
}
else{hist(df[,i],main=names(df)[i],xlim=c(0,300000),breaks=100,xlab=names(df)[i],col=colors)
}
}
