* Graphing. get file='Y:\SPSS\Data\1991 U.S. General Social Survey.sav'. dataset name ds1. frequencies variables=sex. * Counts of a categorical variables. graph /bar = sex. * The same graph, through GGRAPH and GPL. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=sex COUNT() /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: sex=col(source(s), name("sex"), unit.category()) DATA: COUNT=col(source(s), name("COUNT")) GUIDE: axis(dim(2), label("Percent")) ELEMENT: interval(position(summary.percent(sex*COUNT))) END GPL. * Some variations. graph /bar=PCT BY sex. frequencies variables=sex /FORMAT=NOTABLE /*suppress the table so we just get a graph*/ /histogram. graph /histogram sex. * Histograms (for continuous x). descriptives variables=age. graph /histogram(normal)=age. * GGraph version, with additional kernel density overlay. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=age /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: age=col(source(s), name("age")) GUIDE: axis(dim(1), label("Age of Respondent")) GUIDE: axis(dim(2), label("Frequency")) ELEMENT: interval(position(summary.count(bin.rect(age, binWidth(5))))) ELEMENT: line(position(density.normal(age)), color(color.blue)) ELEMENT: line(position(density.kernel.epanechnikov(age)), color(color.red)) END GPL. * Scatterplots. get file="y:\spss\data\employee data.sav" /keep=salary salbegin jobcat. dataset name ds1. graph /scatterplot=salbegin with salary by jobcat. graph /*to emphasize X */ /scatterplot=salbegin with salary /panel rowvar=jobcat. graph /*to emphasize Y */ /scatterplot=salbegin with salary /panel colvar=jobcat. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=salbegin salary /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: salbegin=col(source(s), name("salbegin")) DATA: salary=col(source(s), name("salary")) GUIDE: axis(dim(2), label("Current Salary")) GUIDE: legend(aesthetic(aesthetic.color.interior), label("Employment Category")) ELEMENT: point(position(salbegin*salary)) ELEMENT: line(position(smooth.linear(salbegin*salary))) END GPL. regression /dependent salary /method=enter salbegin /residuals normprob(resid) /* draws a QQ plot */ /save pred (predicted) resid (residuals) /*saves derived values*/. graph /scatterplot(overlay)=salbegin with salary predicted. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=salbegin salary predicted /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: salbegin=col(source(s), name("salbegin")) DATA: salary=col(source(s), name("salary")) DATA: predicted=col(source(s), name("predicted")) GUIDE: axis(dim(2), label("Current Salary")) ELEMENT: point(position(salbegin*salary)) ELEMENT: line(position(salbegin*predicted)) END GPL. graph /histogram (normal) = residuals. graph /scatterplot = predicted with residuals. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=predicted residuals /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: predicted=col(source(s), name("predicted")) DATA: residuals=col(source(s), name("residuals")) GUIDE: axis(dim(2), label("Residuals")) ELEMENT: point(position(predicted*residuals)) ELEMENT: line(position(smooth.loess(predicted*residuals)), color(color.red)) END GPL.