* Horizontal stacked bars. * Visualizing a crosstabulation. get file="Y:\SPSS\Data\Employee data.sav". * We can do this directly with GPL. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=gender COUNT()[name="COUNT"] jobcat /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: gender=col(source(s), name("gender"), unit.category()) DATA: COUNT=col(source(s), name("COUNT")) DATA: jobcat=col(source(s), name("jobcat"), unit.category()) GUIDE: axis(dim(1), label("Gender")) GUIDE: axis(dim(2), label("Percent")) GUIDE: legend(aesthetic(aesthetic.color.interior), label("Employment Category")) SCALE: cat(dim(1), include("f", "m")) SCALE: linear(dim(2), include(0)) SCALE: cat(aesthetic(aesthetic.color.interior), include("1", "2", "3")) COORD: transpose() ELEMENT: interval.stack(position(summary.percent(gender*COUNT, base.coordinate(dim(1)))), color.interior(jobcat), shape.interior(shape.square)) END GPL. * To do this with the GRAPH command, we must first produce a summary data set. * Note that we will end up with a vertical stack, not horizontal, and it would require a template (created with the Chart Editor) to clean up the axis labels. DATASET DECLARE summary. AGGREGATE /OUTFILE='summary' /BREAK=gender jobcat /N_BREAK=N. DATASET ACTIVATE summary. AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK=gender /N_gender=SUM(N_BREAK). compute Percent = (n_break/n_gender)*100. execute. GRAPH /BAR(STACK)=MEAN(Percent) BY gender BY jobcat.