* Encoding: UTF-8. * Checking the chart template. DATASET CLOSE ALL. OUTPUT CLOSE ALL. FILE HANDLE save /NAME = "D:\Dropbox\Dropbox\SPSSInc\SPSS_otherfiles\chart_templates\Examples". * PRESERVE. * SET CTEMPLATE = "". * SET CTEMPLATE = NONE. SET SEED 10. INPUT PROGRAM. LOOP Id = 1 TO 20. END CASE. END LOOP. END FILE. END INPUT PROGRAM. DATASET NAME Test. COMPUTE Group = TRUNC(RV.UNIFORM(1,7)). COMPUTE Pair = RV.BERNOULLI(0.5). COMPUTE X = RV.UNIFORM(0,1). COMPUTE Y = RV.UNIFORM(0,1). COMPUTE Time = MOD(Id-1,10) + 1. COMPUTE TGroup = TRUNC((Id-1)/10). FORMATS Id Group Pair TGroup Time (F2.0) X Y (F2.1). VALUE LABELS Group 1 'A' 2 'B' 3 'C' 4 'D' 5 'E' 6 'F' . VALUE LABELS Pair 0 'Group One' 1 'Group Two' . VARIABLE LABELS Pair 'This is a variable label for pair'. VALUE LABELS TGroup 0 'G1' 1 'G2' . EXECUTE. *Bar graph to show colors, title, legend. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=Group MEAN(X)[name="MEAN"] /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: Group=col(source(s), name("Group"), unit.category()) DATA: X=col(source(s), name("MEAN")) GUIDE: axis(dim(1), label("Group")) GUIDE: axis(dim(2), label("Mean X")) GUIDE: legend(aesthetic(aesthetic.color.interior), label("Group")) GUIDE: text.title(label("Main Title")) GUIDE: text.subtitle(label("Subtitle")) SCALE: cat(dim(1), include("1", "2", "3", "4", "5", "6")) SCALE: linear(dim(2), include(0)) ELEMENT: interval(position(Group*X), shape.interior(shape.square), color.interior(Group)) END GPL. * Scatterplot, showing Y axis trick with subtitle. * Would prefer the setStyle subtype="simple" type="scatter" works as default. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=X Y /GRAPHSPEC SOURCE=INLINE /FITLINE TOTAL=NO. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: X=col(source(s), name("X")) DATA: Y=col(source(s), name("Y")) GUIDE: axis(dim(1), label("X Label")) GUIDE: axis(dim(2)) GUIDE: text.subtitle(label(" Y Label")) ELEMENT: point(position(X*Y), size(size."12"), color.interior(color."bebebe")) END GPL. *Label trick for bar graphs. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=Group COUNT()[name="COUNT"] /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: Group=col(source(s), name("Group"), unit.category()) DATA: COUNT=col(source(s), name("COUNT")) TRANS: ext = eval(COUNT + 0.2) GUIDE: axis(dim(1)) GUIDE: axis(dim(2)) GUIDE: text.subtitle(label("Count")) SCALE: cat(dim(1), include("1", "2", "3", "4", "5", "6")) SCALE: linear(dim(2), include(0)) ELEMENT: interval(position(Group*COUNT), color.interior(color."bebebe")) ELEMENT: polygon(position(Group*ext), label(COUNT), color.interior(color.red), transparency.interior(transparency."1"), transparency.exterior(transparency."1")) END GPL. * Histogram, no summary frame. * Still not happy with Frequency numbers, stat summary is there but is empty. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=Y /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: Y=col(source(s), name("Y")) GUIDE: axis(dim(1), label("Y")) GUIDE: axis(dim(2), label("Frequency")) GUIDE: text.title(label("Simple Histogram of Y")) ELEMENT: interval(position(summary.count(bin.rect(Y, binWidth(0.1), binStart(-0.05) ))), color.interior(color."bebebe"), color.exterior(color.white), transparency.interior(transparency."0.35"), transparency.exterior(transparency."0.35")) END GPL. * Small multiple columns, illustrating different variable formats. COMPUTE XPct = X*100. COMPUTE YDollar = Y * 5000. COMPUTE YComma = Y * 50000. *Can also do PCT3.1, DOLLAR5.2, COMMA 4.1, etc. FORMATS XPct (PCT3) YDollar (DOLLAR4) YComma (COMMA7). EXECUTE. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=XPct YDollar Pair /GRAPHSPEC SOURCE=INLINE /FITLINE TOTAL=NO. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: X=col(source(s), name("XPct")) DATA: Y=col(source(s), name("YDollar")) DATA: Pair=col(source(s), name("Pair"), unit.category()) GUIDE: axis(dim(1), label("X Label")) GUIDE: axis(dim(2), label("Y Label")) GUIDE: axis(dim(4), opposite()) ELEMENT: point(position(X*Y*1*Pair), size(size."12"), color.interior(color."bebebe")) END GPL. * Small multiple rows. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=X YComma Pair /GRAPHSPEC SOURCE=INLINE /FITLINE TOTAL=NO. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: X=col(source(s), name("X")) DATA: Y=col(source(s), name("YComma")) DATA: Pair=col(source(s), name("Pair"), unit.category()) GUIDE: axis(dim(1), label("X Label")) GUIDE: axis(dim(2), label("Y Label")) GUIDE: axis(dim(4), opposite()) ELEMENT: point(position(X*Y*1*Pair)) END GPL. * Small multiple wrap. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=X Y Group /GRAPHSPEC SOURCE=INLINE /FITLINE TOTAL=NO. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: X=col(source(s), name("X")) DATA: Y=col(source(s), name("Y")) DATA: Group=col(source(s), name("Group"), unit.category()) COORD: rect(dim(1,2), wrap()) GUIDE: axis(dim(1)) GUIDE: axis(dim(2)) GUIDE: axis(dim(3), opposite()) ELEMENT: point(position(X*Y*Group)) END GPL. * Multiple line chart (long format). GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=Time Y TGroup /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: Time=col(source(s), name("Time")) DATA: Y=col(source(s), name("Y")) DATA: TGroup=col(source(s), name("TGroup"), unit.category()) SCALE: linear(dim(1), min(1)) GUIDE: axis(dim(1), delta(1)) GUIDE: axis(dim(2)) GUIDE: legend(aesthetic(aesthetic.color.interior)) GUIDE: legend(aesthetic(aesthetic.size), label("Size Y")) GUIDE: text.subtitle(label(" Y")) SCALE: cat(aesthetic(aesthetic.color.interior), include("0", "1")) ELEMENT: line(position(Time*Y), color.interior(TGroup)) ELEMENT: point(position(Time*Y), shape(TGroup), color.interior(TGroup), color.exterior(color.white), size(size."10")) ) END GPL. * Multiple line chart with end labels (wide format). AGGREGATE OUTFILE=* MODE=ADDVARIABLES OVERWRITE=YES /BREAK /LastTime = MAX(Id). IF Id = LastTime IdLabel = Id. FORMATS IdLabel (F2.0). EXECUTE. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=Id X Y IdLabel MISSING=VARIABLEWISE /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: Id=col(source(s), name("Id")) DATA: IdLabel=col(source(s), name("IdLabel")) DATA: X=col(source(s), name("X")) DATA: Y=col(source(s), name("Y")) DATA: TGroup=col(source(s), name("TGroup"), unit.category()) SCALE: linear(dim(1), min(1)) SCALE: linear(dim(2), max(1.08)) GUIDE: axis(dim(1), delta(1)) GUIDE: axis(dim(2)) SCALE: cat(aesthetic(aesthetic.color.interior), include("0", "1")) ELEMENT: line(position(smooth.spline(Id*Y)), color(color.red)) ELEMENT: line(position(smooth.spline(Id*X)), color(color.blue)) ELEMENT: point(position(Id*Y), color.interior(color.red), color.exterior(color.white), size(size."9"), shape(shape.circle)) ELEMENT: point(position(Id*X), color.interior(color.blue), color.exterior(color.white), size(size."8"), shape(shape.square)) ELEMENT: point(position(IdLabel*Y), color(color.red), label("Y"), transparency.interior(transparency."1"), transparency.exterior(transparency."1")) ELEMENT: point(position(IdLabel*X), color(color.blue), label("X"), transparency.interior(transparency."1"), transparency.exterior(transparency."1")) END GPL. * Error Bar chart. VALUE LABELS Pair 0 'Group\nOne' 1 'Group\nTwo' . GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=Pair MEANCI(Y, 95)[name="MEAN_Y" LOW="MEAN_Y_LOW" HIGH="MEAN_Y_HIGH"] MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: Pair=col(source(s), name("Pair"), unit.category()) DATA: MEAN_Y=col(source(s), name("MEAN_Y")) DATA: LOW=col(source(s), name("MEAN_Y_LOW")) DATA: HIGH=col(source(s), name("MEAN_Y_HIGH")) COORD: transpose() GUIDE: axis(dim(1)) GUIDE: axis(dim(2), label("Low Anchor High Anchor", "\nLine 2")) GUIDE: text.title(label("Simple Error Bar Mean of Y by Pair\n[Transposed]")) GUIDE: text.footnote(label("Error Bars: 95% CI")) SCALE: cat(dim(1), include("0", "1"), reverse() ) SCALE: linear(dim(2), include(0)) ELEMENT: interval(position(region.spread.range(Pair*(LOW+HIGH))), shape.interior(shape.ibeam)) ELEMENT: point(position(Pair*MEAN_Y), size(size."12")) END GPL. * Continuous legend example. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=X Y /GRAPHSPEC SOURCE=INLINE /FITLINE TOTAL=NO. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: X=col(source(s), name("X")) DATA: Y=col(source(s), name("Y")) GUIDE: axis(dim(1), label("X Label")) GUIDE: axis(dim(2)) GUIDE: text.subtitle(label(" Y Label")) GUIDE: legend(aesthetic(aesthetic.size), label("SizeLab")) SCALE: linear(dim(2), max(1.05)) SCALE: pow(aesthetic(aesthetic.size), aestheticMinimum(size."6px"), aestheticMaximum(size."30px"), min(0), max(1)) ELEMENT: point(position(X*Y), size(Y), color.interior(color."bebebe")) END GPL. * Multiple legend example. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=X Y Pair /GRAPHSPEC SOURCE=INLINE /FITLINE TOTAL=NO. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: X=col(source(s), name("X")) DATA: Y=col(source(s), name("Y")) DATA: Pair=col(source(s), name("Pair"), unit.category()) GUIDE: axis(dim(1), label("X Label")) GUIDE: axis(dim(2)) GUIDE: text.subtitle(label(" Y Label")) GUIDE: legend(aesthetic(aesthetic.color.interior), label("Color/Shape Lab")) GUIDE: legend(aesthetic(aesthetic.size), label("Size & Trans. Lab")) SCALE: linear(dim(2), max(1.05)) SCALE: linear(aesthetic(aesthetic.size), aestheticMinimum(size."6px"), aestheticMaximum(size."30px"), min(0), max(1)) SCALE: linear(aesthetic(aesthetic.transparency.interior), aestheticMinimum(transparency."0"), aestheticMaximum(transparency."0.6"), min(0), max(1)) ELEMENT: point(position(X*Y), transparency.interior(Y), shape(Pair), size(Y), color.interior(Pair)) END GPL. OUTPUT EXPORT /PNG IMAGEROOT="save\Ex.png". * RESTORE.