I need to create 26 identical graphs, and the only variance is the Y axis
variable to be plotted and the associated variable label to be used in the graph title. I'm struggling to understand how I can use the variable label automatically for each of the 26 graphs. I could either copy and paste the chart syntax 26 times, or use a macro, but in order to use a macro, I need to be able to automatically use the variable label (the label for Q1 is bolded here in this statement)... GUIDE: text.title(label("*PRE Develop leadership skills*")) Here is the full chart builder syntax... * Chart Builder. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=TimePoint MEAN(Q1)[name="MEAN_Q1"] Program MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: TimePoint=col(source(s), name("TimePoint"), unit.category()) DATA: MEAN_Q1=col(source(s), name("MEAN_Q1")) DATA: Program=col(source(s), name("Program"), unit.category()) GUIDE: axis(dim(2), label("Mean 1=blah to 4= blah blah")) GUIDE: legend(aesthetic(aesthetic.color.interior), label("Program")) GUIDE: text.title(label("PRE Develop leadership skills")) GUIDE: text.footnote(label("0 = Blah to 4 = Blah Blah\n")) SCALE: cat(dim(1), include("1", "2")) SCALE: linear(dim(2), include(0)) ELEMENT: line(position(TimePoint*MEAN_Q1), color.interior(Program), missing.wings()) END GPL. -- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
A little Python will do it. First define the chart parametrically... begin program. import spss cmd = """GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=TimePoint MEAN(%(y)s)[name="MEAN_Q1"] Program MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: TimePoint=col(source(s), name("TimePoint"), unit.category()) DATA: MEAN_Q1=col(source(s), name("MEAN_Q1")) DATA: Program=col(source(s), name("Program"), unit.category()) GUIDE: axis(dim(2), label("Mean 1=blah to 4= blah blah")) GUIDE: legend(aesthetic(aesthetic.color.interior), label("Program")) GUIDE: text.title(label("%(ylabel)s")) SCALE: cat(dim(1), include("1", "2")) SCALE: linear(dim(2), include(0)) ELEMENT: line(position(TimePoint*MEAN_Q1), color.interior(Program), missing.wings()) END GPL.""" def plotit(y): ylabel = spssaux.VariableDict().variableLabel(y) spss.Submit(cmd % locals()) end program. Then for each variable... begin program. plotit("salary") end program. That could be modified to take the whole list of variables. On Tue, Oct 1, 2019 at 11:03 AM ChrisKeran <[hidden email]> wrote: I need to create 26 identical graphs, and the only variance is the Y axis |
Thank you, Jon.
When I ran the revised syntax, I received an error at the bottom. FYI, the only change I made was to replace your word "salary" with "Q1". begin program. import spss cmd = """GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=TimePoint MEAN(%(y)s)[name="MEAN_Q1"] Program MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: TimePoint=col(source(s), name("TimePoint"), unit.category()) DATA: MEAN_Q1=col(source(s), name("MEAN_Q1")) DATA: Program=col(source(s), name("Program"), unit.category()) GUIDE: axis(dim(2), label("Mean 1=blah to 4= blah blah")) GUIDE: legend(aesthetic(aesthetic.color.interior), label("Program")) GUIDE: text.title(label("%(ylabel)s")) SCALE: cat(dim(1), include("1", "2")) SCALE: linear(dim(2), include(0)) ELEMENT: line(position(TimePoint*MEAN_Q1), color.interior(Program), missing.wings()) END GPL.""" def plotit(y): ylabel = spssaux.VariableDict().variableLabel(y) spss.Submit(cmd % locals()) end program. begin program. plotit("Q1") end program. Traceback (most recent call last): File "<string>", line 2, in <module> File "<string>", line 22, in plotit NameError: global name 'spssaux' is not defined -- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Add spssaux to the first import statement: import spss, spssaux On Tue, Oct 1, 2019 at 11:57 AM ChrisKeran <[hidden email]> wrote: Thank you, Jon. |
Ah, that was perfect, thank you. Now, how do I modify to take the whole list
of variables (Q1 to Q26)? -- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Redefine plotit. You can put this where the other definition was. begin program. def plotit(*varlist): for y in varlist: ylabel = spssaux.VariableDict().variableLabel(y) spss.Submit(cmd % locals()) end program. Use it like this. begin program. plotit("salary", "salbegin") end program. On Tue, Oct 1, 2019 at 12:01 PM ChrisKeran <[hidden email]> wrote: Ah, that was perfect, thank you. Now, how do I modify to take the whole list |
That worked fantastic! Thank you. FYI, here is the final working syntax (but
only using for 3 variables so far)... begin program. import spss, spssaux cmd = """GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=TimePoint MEAN(%(y)s)[name="MEAN_Q1"] Program MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: TimePoint=col(source(s), name("TimePoint"), unit.category()) DATA: MEAN_Q1=col(source(s), name("MEAN_Q1")) DATA: Program=col(source(s), name("Program"), unit.category()) GUIDE: axis(dim(2), label("Mean 1=blah to 4= blah blah")) GUIDE: legend(aesthetic(aesthetic.color.interior), label("Program")) GUIDE: text.title(label("%(ylabel)s")) SCALE: cat(dim(1), include("1", "2")) SCALE: linear(dim(2), include(0)) ELEMENT: line(position(TimePoint*MEAN_Q1), color.interior(Program), missing.wings()) END GPL.""" end program. begin program. def plotit(*varlist): for y in varlist: ylabel = spssaux.VariableDict().variableLabel(y) spss.Submit(cmd % locals()) end program. *Use it like this. begin program. plotit("Q1", "Q2", "Q3") end program. -- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Great. One more tip. If your variable list gets too long for the syntax line length limit, you can split it across lines at a comma. E.g., begin program. plotit("salary", "salbegin") end program. On Tue, Oct 1, 2019 at 12:52 PM ChrisKeran <[hidden email]> wrote: That worked fantastic! Thank you. FYI, here is the final working syntax (but |
Thanks, Jon.
Say, how come this line doesn't work when I include it? It worked before we added the automation. GUIDE: text.footnote(label("0 = Blah to 4 = Blah Blah\n")) -- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
It's that extra newline (\n) there. It's causing a line break in the literal without proper quoting. Just remove it. On Tue, Oct 1, 2019 at 2:00 PM ChrisKeran <[hidden email]> wrote: Thanks, Jon. |
Ah, that was it, thank you.
-- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Can you help me to include text on the 2nd line of the title?
I attempted to modify this line, but it isn't quite working... GUIDE: text.title(label("%(ylabel)s", \n "Notes")) begin program. import spss, spssaux cmd = """GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=TimePoint MEAN(%(y)s)[name="MEAN_Q1"] Program MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: TimePoint=col(source(s), name("TimePoint"), unit.category()) DATA: MEAN_Q1=col(source(s), name("MEAN_Q1")) DATA: Program=col(source(s), name("Program"), unit.category()) GUIDE: axis(dim(2), label("Mean: 0=Not at all confident to 4=Very confident")) GUIDE: legend(aesthetic(aesthetic.color.interior), label("Program")) GUIDE: text.title(label("%(ylabel)s", \n "Notes")) GUIDE: text.footnote(label("0=Not at all confident to 4=Very confident")) SCALE: cat(dim(1), include("1", "2")) SCALE: linear(dim(2), min(0), max(4)) ELEMENT: line(position(TimePoint*MEAN_Q1), color.interior(Program), missing.wings()) END GPL.""" end program. begin program. def plotit(*varlist): for y in varlist: ylabel = spssaux.VariableDict().variableLabel(y) spss.Submit(cmd % locals()) end program. *Run the plots. begin program. plotit("Q1", "Q2", "Q3") end program. -- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
-----Ursprungligt meddelande-----
Från: SPSSX(r) Discussion [mailto:[hidden email]] För ChrisKeran Skickat: den 8 oktober 2019 20:38 Till: [hidden email] Ämne: Re: Auto title in GGraph Can you help me to include text on the 2nd line of the title? I attempted to modify this line, but it isn't quite working... GUIDE: text.title(label("%(ylabel)s", \n "Notes")) begin program. import spss, spssaux cmd = """GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=TimePoint MEAN(%(y)s)[name="MEAN_Q1"] Program MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: TimePoint=col(source(s), name("TimePoint"), unit.category()) DATA: MEAN_Q1=col(source(s), name("MEAN_Q1")) DATA: Program=col(source(s), name("Program"), unit.category()) GUIDE: axis(dim(2), label("Mean: 0=Not at all confident to 4=Very confident")) GUIDE: legend(aesthetic(aesthetic.color.interior), label("Program")) GUIDE: text.title(label("%(ylabel)s", \n "Notes")) GUIDE: text.footnote(label("0=Not at all confident to 4=Very confident")) SCALE: cat(dim(1), include("1", "2")) SCALE: linear(dim(2), min(0), max(4)) ELEMENT: line(position(TimePoint*MEAN_Q1), color.interior(Program), missing.wings()) END GPL.""" end program. begin program. def plotit(*varlist): for y in varlist: ylabel = spssaux.VariableDict().variableLabel(y) spss.Submit(cmd % locals()) end program. *Run the plots. begin program. plotit("Q1", "Q2", "Q3") end program. -- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
In reply to this post by ChrisKeran
Instead of GUIDE: text.title(label("%(ylabel)s", \n "Notes")) write GUIDE: text.title(label("%(ylabel)s\\nNotes")) On Tue, Oct 8, 2019 at 12:29 PM ChrisKeran <[hidden email]> wrote: Can you help me to include text on the 2nd line of the title? |
That worked great, thanks Jon.
Is there a way within the GGraph command to make the 1st line of the title have a larger font size (and leave the 2nd line as is)? If not possible within GGraph, perhaps using Modify Output Titles? Thanks, Chris -- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
If you use the title and subtitle functions, the subtitle will be in a smaller font by default. GUIDE: text.title(label("main title")) GUIDE: text.subsubtitle(label("subtitle")) On Wed, Oct 9, 2019 at 8:04 AM ChrisKeran <[hidden email]> wrote: That worked great, thanks Jon. |
Nice, thanks.
-- Sent from: http://spssx-discussion.1045642.n5.nabble.com/ ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
Free forum by Nabble | Edit this page |