So the other day after my fluctuation chart post Jon Peck gently nudged me to make a
chart custom dialog (with teasers such as it only takes a few minutes.) Well, he is right, they are quite easy to make. Here I will briefly walk through the process just to highlight how easy it really is.
At first, I was confusing the custom builder dialog with the old VB like scripts. The newer builder dialog (not sure what version it was introduced, but all I note here was produced in V20) is a purely GUI application that one can build dialogs to insert arbitrary code sections based on user input. It is easier to show than say, but in the end the dialog I build here will produce the necessary syntax to make the fluctuation charts I showed in the noted prior post.
So first, to get to the Chart Builder dialog one needs to access the menu via Utilities -> Custom Dialogs -> Custom Dialog Builder.
Then, when the dialog builder is opened, one is presented with an empty dialog canvas.
To start building the dialog, you drag the elements in the tool box onto the canvas. It seems you will pretty much always want to start with a source variable list.
Now, before we finish all of the controls, lets talk about how the dialog builder interacts with the produced syntax. So, for my fluctuation chart, a typical syntax call might look like below, if we want to plot
GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=V1 V2 COUNT()[name="COUNT"] /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: V1=col(source(s), name("V1"), unit.category()) DATA: V2=col(source(s), name("V2"), unit.category()) DATA: COUNT=col(source(s), name("COUNT")) GUIDE: axis(dim(1), label("V1")) GUIDE: axis(dim(2), label("V2")) SCALE: pow(aesthetic(aesthetic.size), aestheticMinimum(size."8px"), aestheticMaximum(size."45px")) SCALE: linear(aesthetic(aesthetic.color.interior), aestheticMinimum(color.lightgrey), aestheticMaximum(color.darkred)) ELEMENT: point(position(V1*V2), shape(shape.square), color.interior(COUNT), size(COUNT)) END GPL.
So how exactly will the dialog builder insert arbitrary variables? In our syntax, we want to replace sections of code with
%%Identifier%%, where Identifier refers to a particular name we assign to any particular control in the builder. So, if I wanted to have some arbitrary code to change
V1 to whatever the user inputs, I would replace
V1 in the original syntax with
%%myvar%% (and name the control
myvar). In the end, the syntax template for this particular dialog looks like below.
GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=%%x%% %%y%% COUNT()[name="COUNT"] /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: %%x%%=col(source(s), name("%%x%%"), unit.category()) DATA: %%y%%=col(source(s), name("%%y%%"), unit.category()) DATA: COUNT=col(source(s), name("COUNT")) GUIDE: axis(dim(1), label("%%x%%")) GUIDE: axis(dim(2), label("%%y%%")) %%title%% SCALE: pow(aesthetic(aesthetic.size) %%minpixel%% %%maxpixel%%) SCALE: linear(aesthetic(aesthetic.color.interior), aestheticMinimum(color.lightgrey), aestheticMaximum(color.darkred)) ELEMENT: point(position(%%x%%*%%y%%), shape(shape.square), color.interior(COUNT), size(COUNT)) END GPL.
To insert the syntax, there is a button in the dialog builder to open it (the tool tip will say syntax template). You can just copy and paste the code in. Here there are user inputs for both the variables for the fluctuation chart, and the minimum and maximum size of the pixels, and the chart title. Only the variables are required for execution, and if the user inputs for the other arbitrary statements are not filled in they dissapear completely from the syntax generation.
Now, we are set up with all of the arbitrary elements we want to insert into the code. Here I want to have controls for two target lists (the x and y axis variables), two number controls (for the min and max size of the pixels), and one text control (for the chart title). To associate the control with the syntax, after you place a control on the canvas you can select and edit its attributes. The Identifier attribute is what associates it with the
%%mypar%% in the syntax template.
So here for the Y axis variable, I named the Identifier
Also take note of the syntax field,
%%ThisValue%%. Here, you can change the syntax field to either just enter the field name (or user input), or enter in more syntax around that user input. As an example, the Syntax field for the Chart Title control looks like this;
If the title control is omitted, the entire
%%title%% line in the syntax template is not generated. If some text is entered into the title control, the surrounding
GUIDE syntax is inserted with the text replacing
%%ThisValue%% in the above code example. You can see how I used this behavior to make the min and max pixel size for the points arbitrary.
To learn more about all of the different controls and more of the aesthetics and extra niceties you can do with the dialog builder, you should just take a stroll through the help for custom dialogs. Here is the location where I uploaded the FluctuationChart dialog builder to (you can open it up and edit it yourself to see the internals). I hope to see more contributions by other SPSS users in the future, they are really handy for Python and R scripts in addition to GGRAPH code.