I thought there was a python
extension command to simply substitute a variable name, but I cannot come up with its name.
I have a data set with 19 rows (years) and 22 columns each of which have variable labels. The variable "year" is just the number for the year I would like to produce 22 separate line charts. I would like all the charts to have the same look. -- They would all have the full range of years on the X axis even if there the early years are missing. -- they would all have a Y axis of -3 -2 - 1 0 1 2 3. -- the lines would only connect valid values. -- there would be a reference line a Y = 0. I tried creating a template and I can have the ticks the way I want them. I cannot get the reference line at Y=0 nor the full range of years when some are missing. below is some data for 4 variables. data list list/ year(f4) zscore1 to zscore4 (4f6.2). begin data 1993 -.25 -2.08 . -1.33 1994 -.66 -1.73 . -1.19 1995 -.36 -1.65 . -1.19 1996 -.68 -1.37 . -.98 1997 -1.25 .07 . -.94 1998 -.79 .16 1.10 -.87 1999 .25 .59 1.48 -.49 2000 .13 1.03 1.38 -.45 2001 .17 1.00 1.27 -.14 2002 -.93 .15 .76 -.35 2003 -.36 .02 .46 -.35 2004 -.02 -.50 -.91 .21 2004 1.62 -.09 -.83 .53 2006 2.36 .51 -.83 .98 2007 1.69 .83 -.82 1.16 2008 .76 .85 -.73 1.47 2009 .23 .95 -.60 1.68 2010 -.67 .69 -.81 1.30 2011 -1.23 .57 -.93 .91 end data. variable labels Zscore1 'some set of words' Zscore2 'A second set of words' Zscore3 'third set of words' Zscore4 'words and words'. * Chart Builder. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=year zscore1 MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE TEMPLATE=[ "C:\Users\Art\Desktop\z over years.sgt"]. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: year=col(source(s), name("year")) DATA: zscore1=col(source(s), name("zscore1")) GUIDE: axis(dim(1), label("year")) GUIDE: axis(dim(2), label("some set of words")) ELEMENT: line(position(year*zscore1), missing.wings()) END GPL. -- Art Kendall Social Research Consultants z over years.sgt (5K) Download Attachment
Art Kendall
Social Research Consultants |
Reference Line:
GUIDE: form.line(position(*,0)) Restricting the y axis range and making tick marks every integer unit (also FYI if you specify the format for the variable to be F1.0 the chart won't display needless decimals). SCALE: linear(dim(2), min(-3), max(3)) GUIDE: axis(dim(2), label("some set of words"), delta(1), start(-3)) Full range of years: SCALE: linear(dim(1), min(1993), max(2011)) GUIDE: axis(dim(1), label("year"), delta(1), start(1993)) Lines only connecting at valid values: ELEMENT: line(position(year*zscore1), missing.gap()) For the reference line you can specify various aesthetics. For the scale the template contains a default % below and % above for continous scales. See this recent question related to repeating the same chart multiple times, http://spssx-discussion.1045642.n5.nabble.com/Repeating-GPL-structure-td5720430.html#a5720432, references to both a split files and a python solution included. |
Thank you. I almost
have the graph I need for a single variable. However, the
tick labels on the
Y Axis do not show all
of the years.
When I have that part right I'll try the Python approach to do the set of variables. I have attached the syntax with example data and drawing the graph. Note the tick labels on the X axis. I also attached the .sgt file. Art Kendall Social Research ConsultantsOn 6/10/2013 8:08 AM, Andy W [via SPSSX Discussion] wrote: Reference Line:
Art Kendall
Social Research Consultants |
Your code produces the correct tick marks ever integer on the y axis (and years on the x axis) for me (V15). How the templates behave though have changed slightly between versions. Sometimes templates and defined attributes in inline GPL don't play nicely together (that is, for some things the template gets preference). May be worth trying without a template to see if it works, and then save a new chart template.
|
Thank you one again. It ran without
a template.
Art Kendall Social Research ConsultantsOn 6/10/2013 2:42 PM, Andy W [via SPSSX Discussion] wrote: Your code produces the correct tick marks ever integer on the y axis (and years on the x axis) for me (V15). How the templates behave though have changed slightly between versions. Sometimes templates and defined attributes in inline GPL don't play nicely together (that is, for some things the template gets preference). May be worth trying without a template to see if it works, and then save a new chart template. for list.sps (2K) Download Attachment
Art Kendall
Social Research Consultants |
In reply to this post by Andy W
Its always the little
things!
I did not check the out put carefully enough. The attached syntax just uses the variable name. is there a way to have the variable label as the label on the Y axis. Or failing that to put it in a title on the graph? Art Kendall Social Research ConsultantsOn 6/10/2013 2:42 PM, Andy W [via SPSSX Discussion] wrote: Your code produces the correct tick marks ever integer on the y axis (and years on the x axis) for me (V15). How the templates behave though have changed slightly between versions. Sometimes templates and defined attributes in inline GPL don't play nicely together (that is, for some things the template gets preference). May be worth trying without a template to see if it works, and then save a new chart template. for list.sps (2K) Download Attachment
Art Kendall
Social Research Consultants |
For variable labels you will need to pursue the python route. For a simple chart title though I've suggested to utilize varstocases and then split files. Example below.
***************************************************. data list list/ year(f4) zscore1 to zscore4 (4f6.2). begin data 1993 -.25 -2.08 . -1.33 1994 -.66 -1.73 . -1.19 1995 -.36 -1.65 . -1.19 1996 -.68 -1.37 . -.98 1997 -1.25 .07 . -.94 1998 -.79 .16 1.10 -.87 1999 .25 .59 1.48 -.49 2000 .13 1.03 1.38 -.45 2001 .17 1.00 1.27 -.14 2002 -.93 .15 .76 -.35 2003 -.36 .02 .46 -.35 2004 -.02 -.50 -.91 .21 2004 1.62 -.09 -.83 .53 2006 2.36 .51 -.83 .98 2007 1.69 .83 -.82 1.16 2008 .76 .85 -.73 1.47 2009 .23 .95 -.60 1.68 2010 -.67 .69 -.81 1.30 2011 -1.23 .57 -.93 .91 end data. variable labels Zscore1 'some set of words' Zscore2 'A second set of words' Zscore3 'third set of words' Zscore4 'words and words'. varstocases /make Zscore from Zscore1 to Zscore4 /index Lab /null = keep. value label Lab 1 'some set of words' 2 'A second set of words' 3 'third set of words' 4 'words and words'. formats Zscore (F1.0). *PRESERVE. *SET CTEMPLATE="D:\Temp\Art_GPLGuide\z over years.sgt". sort cases by Lab year. split file by Lab. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=year zscore MISSING=VARIABLEWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: year=col(source(s), name("year")) DATA: zscore=col(source(s), name("zscore")) TRANS: gl=eval(0) SCALE: linear(dim(1), min(1993), max(2011)) SCALE: linear(dim(2), min(-3), max(3)) GUIDE: axis(dim(1), label("year"), delta(1), start(1993)) GUIDE: axis(dim(2), label("Zscore"), delta(1), start(-3)) ELEMENT: line(position(year*gl), color(color.grey), size(size."2"), shape.interior(shape.dash)) ELEMENT: line(position(year*zscore), missing.gap(), color(color.black), size(size."1")) ELEMENT: point(position(year*zscore), color.exterior(color.white), color.interior(color.black), size(size."8")) END GPL. split file off. *RESTORE. ***************************************************. Other notes, I have an older version that doesn't support guidelines, so I utilize the TRANS function to create one (and because of this specify missing variablewise). Also note in your prior version you drew the guideline on top of the elements, something I doubt is desirable. I omitted using your template, because as I said it did not play nicely with the specified aesthetics in inline GPL. (Note sure off-hand if there is an easy way to make sure the digits don't display the grouping - maybe only way is via template or specifying that years are categorical.) The double point is as intended - you had a data error in your original data listing (2004 twice). Something more difficult (but not impossible) to discern with only the line. (Also note missing gap does not behave as expected - the GPL doesn't know 2005 is missing in continuous data - it only knows that the sequential data elements in the file aren't missing.) |
Free forum by Nabble | Edit this page |