Posted by
Andy W on
Oct 17, 2021; 1:41pm
URL: http://spssx-discussion.165.s1.nabble.com/Data-dependent-Reference-line-in-GPL-tp5740795p5740798.html
I don't use the mailing list (my email summaries said there was some back and forth), but just answer on nabble.
Here is how I do this typically.
*****************************************.
DATA LIST FREE / X Y.
BEGIN DATA
1 1
2 0
3 1
4 0
END DATA.
DATASET NAME Sim.
EXECUTE.
AGGREGATE OUTFILE=* MODE=ADDVARIABLES
/BREAK
/MX = MEAN(X)
/MY = MEAN(Y).
EXECUTE.
*Example vertical line red.
*Example horizontal line blue.
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=X Y MX MY
/GRAPHSPEC SOURCE=INLINE
/FITLINE TOTAL=NO SUBGROUP=NO.
BEGIN GPL
SOURCE: s=userSource(id("graphdataset"))
DATA: X=col(source(s), name("X"))
DATA: Y=col(source(s), name("Y"))
DATA: MX=col(source(s), name("MX"))
DATA: MY=col(source(s), name("MY"))
GUIDE: axis(dim(1), label("X"))
GUIDE: axis(dim(2), label("Y"))
ELEMENT: point(position(X*Y), size(size."12"))
ELEMENT: edge(position(region.spread.range(MX*Y)),color(color.red))
ELEMENT: line(position(X*MY),color(color.blue))
END GPL.
*****************************************.
This is somewhat different than using GUIDE, which will extend the line 100% of the graph area. If you want to use this like GUIDE, you need to explicitly set the SCALE min/max, and then have the data extend beyond those limits. (But often just going the data length is OK for my graphs.)