Apologies to those who have seen this on the now disconnected SPSSX list!
I am trying to display reference lines on a date formatted axis. I am obviously not specifying the date position correctly for the line but cannot work out what it should be: your wisdom would be appreciated Syntax below generates an example with 3 form lines but only the one on the numerical y axis is shown. cheers Jeremy * Encoding: UTF-8. DATA LIST FREE / Date (date11) Growth (F2.1). BEGIN DATA 06-Sep-2020 .00 06-Apr-2020 .32 12-Aug-2020 .00 15-Jun-2020 .00 18-Jun-2020 .00 16-Jun-2020 .00 18-Jun-2020 .00 09-Aug-2020 .00 31-Jul-2020 .00 04-Sep-2020 .01 10-Oct-2020 .01 12-Oct-2020 .00 END DATA. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=Date Growth MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: Date=col(source(s), name("Date")) DATA: Growth=col(source(s), name("Growth")) GUIDE: axis(dim(1), label("Date")) GUIDE: axis(dim(2), label("Growth")) GUIDE: form.line(position(13811558400, *)) GUIDE: form.line(position("15-Jun-2020", *)) GUIDE: form.line(position(*, 0.2)) ELEMENT: line(position(Date*Growth), missing.wings()) END GPL |
There might be a better way, but if you set the variable type of the date variable to numeric, you see this.
13,818,729,600 13,805,510,400 13,816,569,600 13,811,558,400 13,811,817,600 13,811,644,800 13,811,817,600 13,816,310,400 13,815,532,800 13,818,556,800 13,821,667,200 13,821,840,000 If you enter those values (without the commas) in GUIDE statements, you get the reference lines you want. GUIDE: form.line(position(13811558400, *)) |
Administrator
|
Hi Jon. Jeremy did have that GUIDE statement (plus a couple others) in the code he posted. If I remove the other GUIDE statements, it still does not work. To get the desired X-axis reference line, I have to use a numeric date variable. But then the X-axis labels are also numeric, and I suspect Jeremy wants those labels to be formatted as dates. So that raises another question: Is there a way in GPL to make numeric values on the X-axis display as dates?
Here's my code. NEW FILE. DATASET CLOSE ALL. DATA LIST FREE / Date (date11) Growth (F2.1). BEGIN DATA 06-Sep-2020 .00 06-Apr-2020 .32 12-Aug-2020 .00 15-Jun-2020 .00 18-Jun-2020 .00 16-Jun-2020 .00 18-Jun-2020 .00 09-Aug-2020 .00 31-Jul-2020 .00 04-Sep-2020 .01 10-Oct-2020 .01 12-Oct-2020 .00 END DATA. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=Date Growth MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: datenum=col(source(s), name("Date")) DATA: Growth=col(source(s), name("Growth")) GUIDE: axis(dim(1), label("Date")) GUIDE: axis(dim(2), label("Growth")) /**********************************************/ GUIDE: form.line(position(13811558400, *)) /**********************************************/ GUIDE: form.line(position(*, 0.2)) ELEMENT: line(position(datenum*Growth), missing.wings()) END GPL. * I see no reference line at X=13811558400. COMPUTE datenum = date. FORMATS datenum (F15.0). LIST datenum date. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=Datenum Growth MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: datenum=col(source(s), name("Datenum")) DATA: Growth=col(source(s), name("Growth")) GUIDE: axis(dim(1), label("Date")) GUIDE: axis(dim(2), label("Growth")) GUIDE: form.line(position(13811558400, *)) GUIDE: form.line(position(*, 0.2)) ELEMENT: line(position(datenum*Growth), missing.wings()) END GPL. * Now I see a reference line at X=13811558400, but * the X-axis labels are no longer formatted as dates. * I suspect Jeremy wants the reference line AND to * have the X-axis labels formatted as dates, as they * are in the first graph.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Thanks for the clarification Bruce. That's exactly what I am after. Using FORMATS Date (F12) and then unit.time in the DATA: statement does not work either
|
Administrator
|
Is there an equivalent of the Bat Signal we can activate to get Andy Wheeler's attention?
Nana nana nana nana, Nana nana nana nana, Graphman, Graphman, Graphman!
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
IIRC, this has been the behavior for along time. A workaround is to create data and pass that into the graph function to draw the line. Approximate outline (appears I need to update SPSS license, so cannot test myself right away):
- create a new date variable for 6/15/2020, have it only fill in one row - include this new variable in the GRAPHDATASET line, set MISSING=VARIABLEWISE - create a new edge element, something like: TRANS: bottom=eval(-1) TRANS: top = eval(1) ELEMENT: edge(position((DateVar*bottom)+(DateVar*top)) (Note, I am not sure if TRANS will play nice with missing data. If not, create a variable in the dataset bottom/top and pass that in same as the new DateVar.) - You may need to set the scale of the graph now, as it may extend to encompass your line. To get the behavior of form.line you want it to scale the entire plot area. SCALE: linear(dim(2), min(0), max(0.35)) |
In reply to this post by JeremyT
A working solution is to specify the reference line with a full ISO 8601 string, ie "YYYY-MM-DDTHH-MM-SS.sss": "2020-06-15T00:00:00.000". Apparently the GPL is quite picky about parameters...
I also changed the line size and shape. HTH /PR https://en.wikipedia.org/wiki/ISO_8601 GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=Date Growth MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: Date=col(source(s), name("Date")) DATA: Growth=col(source(s), name("Growth")) GUIDE: axis(dim(1), label("Date")) GUIDE: axis(dim(2), label("Growth")) GUIDE: form.line(position("2020-06-15T00:00:00.000", *), shape(shape.dash), size(size."2px")) GUIDE: form.line(position(*, 0.2)) ELEMENT: line(position(Date*Growth), missing.wings()) END GPL.
|
Administrator
|
Well done, Peder. That cracks it.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Thanks to both Andy and PRogman for solving this. I also tried using, after Andy's reply, interval.range which also worked but both got complicated when I tried to add a lot of lines. PRogman's is perfect, but what now interests me is where did you find the detail to solve this?
cheers Jeremy |
Free forum by Nabble | Edit this page |