GGRAPH Scatterplot: Any way to "Attach label to line" via syntax?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

GGRAPH Scatterplot: Any way to "Attach label to line" via syntax?

Bruce Weaver
Administrator
Here's some syntax that illustrates my problem.

* Generate some data to illustrate.

PRESERVE.
SET RNG=MT MTINDEX=20130709.
NEW FILE.
DATASET CLOSE all.

INPUT PROGRAM.
LOOP Group = 1 to 2.
LEAVE Group.
LOOP # = 1 to 50.
END CASE.
END LOOP.
END LOOP.
END FILE.
END INPUT PROGRAM.
COMPUTE X = RV.NORMAL(50,10).
IF Group EQ 1 Y = 25 + .60*X + RV.NORMAL(0,5).
IF Group EQ 2  Y = 25 + .50*X + RV.NORMAL(0,5).
EXECUTE.
FORMATS Group (F1).

* Scatterplot with separate regression lines for each group.

GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=X Y Group MISSING=LISTWISE REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: X=col(source(s), name("X"))
  DATA: Y=col(source(s), name("Y"))
  DATA: Group=col(source(s), name("Group"), unit.category())
  GUIDE: axis(dim(1), label("X"))
  GUIDE: axis(dim(2), label("Y"))
  GUIDE: legend(aesthetic(aesthetic.color.exterior), label("Group"))
  ELEMENT: point(position(X*Y), color.exterior(Group))
  GUIDE: legend(aesthetic(aesthetic.shape.interior), label("Group"))
  SCALE: cat(aesthetic(aesthetic.color.interior))
  ELEMENT: line(position(smooth.linear(X*Y)), color.interior(Group))
END GPL.

If all works properly for you, you should see a scatterplot with two regression lines on it, one for each group.  If you open the chart editor (by double-clicking on the chart) and double-click on one of the regression lines, a Properties dialog should appear.  Near the bottom of that dialog, there is a "Attach label to line" check-box that is unchecked.  If you check it, the two regression equations will be displayed on the scatter-plot (attached to their respective lines).  

QUESTION:  Is there a GGRAPH option to check that "Attach label to line" box (so to speak) via syntax?  

I have searched for "attach label to line" and "attach label" in the GPL Reference Guide (and in the FM), and have not found anything.

Thanks.

--
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/).
Reply | Threaded
Open this post in threaded view
|

Re: GGRAPH Scatterplot: Any way to "Attach label to line" via syntax?

ViAnn Beadle
Use a label() function on the line ELEMENT.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Bruce Weaver
Sent: Thursday, July 23, 2015 4:14 PM
To: [hidden email]
Subject: GGRAPH Scatterplot: Any way to "Attach label to line" via syntax?

Here's some syntax that illustrates my problem.

* Generate some data to illustrate.

PRESERVE.
SET RNG=MT MTINDEX=20130709.
NEW FILE.
DATASET CLOSE all.

INPUT PROGRAM.
LOOP Group = 1 to 2.
LEAVE Group.
LOOP # = 1 to 50.
END CASE.
END LOOP.
END LOOP.
END FILE.
END INPUT PROGRAM.
COMPUTE X = RV.NORMAL(50,10).
IF Group EQ 1 Y = 25 + .60*X + RV.NORMAL(0,5).
IF Group EQ 2  Y = 25 + .50*X + RV.NORMAL(0,5).
EXECUTE.
FORMATS Group (F1).

* Scatterplot with separate regression lines for each group.

GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=X Y Group MISSING=LISTWISE
REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: X=col(source(s), name("X"))
  DATA: Y=col(source(s), name("Y"))
  DATA: Group=col(source(s), name("Group"), unit.category())
  GUIDE: axis(dim(1), label("X"))
  GUIDE: axis(dim(2), label("Y"))
  GUIDE: legend(aesthetic(aesthetic.color.exterior), label("Group"))
  ELEMENT: point(position(X*Y), color.exterior(Group))
  GUIDE: legend(aesthetic(aesthetic.shape.interior), label("Group"))
  SCALE: cat(aesthetic(aesthetic.color.interior))
  ELEMENT: line(position(smooth.linear(X*Y)), color.interior(Group)) END
GPL.

If all works properly for you, you should see a scatterplot with two
regression lines on it, one for each group.  If you open the chart editor
(by double-clicking on the chart) and double-click on one of the regression
lines, a Properties dialog should appear.  Near the bottom of that dialog,
there is a "Attach label to line" check-box that is unchecked.  If you check
it, the two regression equations will be displayed on the scatter-plot
(attached to their respective lines).  

*QUESTION*:  Is there a GGRAPH option to check that "Attach label to line"
box (so to speak) via syntax?  

I have searched for "attach label to line" and "attach label" in the GPL
Reference Guide (and in the FM), and have not found anything.

Thanks.





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/GGRAPH-Scatterplot-Any-way-to-
Attach-label-to-line-via-syntax-tp5730273.html
Sent from the SPSSX Discussion mailing list archive at 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
Reply | Threaded
Open this post in threaded view
|

Re: GGRAPH Scatterplot: Any way to "Attach label to line" via syntax?

Andy W
That is true ViAnn, that adding a label element in the GPL will associate a label with each fit line. But, to get the same regression equation as a label Bruce is talking about one needs to have that label as a string somewhere already in the data, not calculated on the fly.

I exported the chart template and dug around a bit, but did not see anything that looked like a feasible option to turn this on. There is a part to add the summary information to the legend on the right hand side of the plot:

        <addFrame count="0" type="statisticsSummary">
                <label><style color="#000000" color2="transparent" coordinate="0" font-family="Calibri" font-size="8pt" font-weight="regular" labelLocationHorizontal="center" labelLocationVertical="center" number="0" opacity2="0.0" stroke-opacity="0.0" visible="true"/></label>
        </addFrame> 

And then there is a option to add a reference line, with the data for group 2 specified.

        <addReferenceLine styleOnly="true" y="24.8+0.47*x" ycategorical="false">
                <style color="transparent" visible="true"/>
                <style color="transparent" visible="true"/>
        </addReferenceLine>

But I don't think either of these can be manipulated to do what Bruce wants.

There is always the option of calculating the line and adding it somewhere in the data as a string, but that is a pain in the behind.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: GGRAPH Scatterplot: Any way to "Attach label to line" via syntax?

Bruce Weaver
Administrator
In reply to this post by ViAnn Beadle
Thanks ViAnn.  That points me in the right direction.  I need something like this:

  ELEMENT: line(position(smooth.linear(X*Y)), color.interior(Group), label(X))

But I can't immediately find what the X is that I need to replace in that label(X).  Here are a couple things I've tried, both without success.

1. X = "Group"
Result:  Both lines labeled with the word "Group"

2. X = smooth.linear(X*Y)
Result:  GPL Translation error -- no plot generated

3. X = position(smooth.linear(X*Y))
Result:  GPL Translation error -- no plot generated

So, as you can see, I need help figuring out what X has to be in order to display the equations for each line.  Any thoughts?  

By the way, in the actual application, I'll probably have situations where I want to display the equations for both linear and quadratic fits.

Thanks,
Bruce
 

ViAnn Beadle wrote
Use a label() function on the line ELEMENT.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Bruce Weaver
Sent: Thursday, July 23, 2015 4:14 PM
To: [hidden email]
Subject: GGRAPH Scatterplot: Any way to "Attach label to line" via syntax?

Here's some syntax that illustrates my problem.

* Generate some data to illustrate.

PRESERVE.
SET RNG=MT MTINDEX=20130709.
NEW FILE.
DATASET CLOSE all.

INPUT PROGRAM.
LOOP Group = 1 to 2.
LEAVE Group.
LOOP # = 1 to 50.
END CASE.
END LOOP.
END LOOP.
END FILE.
END INPUT PROGRAM.
COMPUTE X = RV.NORMAL(50,10).
IF Group EQ 1 Y = 25 + .60*X + RV.NORMAL(0,5).
IF Group EQ 2  Y = 25 + .50*X + RV.NORMAL(0,5).
EXECUTE.
FORMATS Group (F1).

* Scatterplot with separate regression lines for each group.

GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=X Y Group MISSING=LISTWISE
REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: X=col(source(s), name("X"))
  DATA: Y=col(source(s), name("Y"))
  DATA: Group=col(source(s), name("Group"), unit.category())
  GUIDE: axis(dim(1), label("X"))
  GUIDE: axis(dim(2), label("Y"))
  GUIDE: legend(aesthetic(aesthetic.color.exterior), label("Group"))
  ELEMENT: point(position(X*Y), color.exterior(Group))
  GUIDE: legend(aesthetic(aesthetic.shape.interior), label("Group"))
  SCALE: cat(aesthetic(aesthetic.color.interior))
  ELEMENT: line(position(smooth.linear(X*Y)), color.interior(Group))
END GPL.

If all works properly for you, you should see a scatterplot with two
regression lines on it, one for each group.  If you open the chart editor
(by double-clicking on the chart) and double-click on one of the regression
lines, a Properties dialog should appear.  Near the bottom of that dialog,
there is a "Attach label to line" check-box that is unchecked.  If you check
it, the two regression equations will be displayed on the scatter-plot
(attached to their respective lines).  

*QUESTION*:  Is there a GGRAPH option to check that "Attach label to line"
box (so to speak) via syntax?  

I have searched for "attach label to line" and "attach label" in the GPL
Reference Guide (and in the FM), and have not found anything.

Thanks.





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/GGRAPH-Scatterplot-Any-way-to-
Attach-label-to-line-via-syntax-tp5730273.html
Sent from the SPSSX Discussion mailing list archive at 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
--
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/).
Reply | Threaded
Open this post in threaded view
|

Re: GGRAPH Scatterplot: Any way to "Attach label to line" via syntax?

ViAnn Beadle
In reply to this post by Andy W
I assume that you want to solve for equation and not just pass along a string. I wonder if the TRANS statement could be used to do that. Otherwise, I'm thinking that this might involve python.
Reply | Threaded
Open this post in threaded view
|

Re: GGRAPH Scatterplot: Any way to "Attach label to line" via syntax?

Bruce Weaver
Administrator
Given that the manual Chart Editor steps I described in my first post result in the two equations being attached to their respective lines, I assume those equations must be stored somewhere as part of the chart, and I was hoping to get access to them via some GPL function.  But judging from what you and Andy have said, I am probably out of luck.

Thanks,
Bruce


ViAnn Beadle wrote
I assume that you want to solve for equation and not just pass along a string. I wonder if the TRANS statement could be used to do that. Otherwise, I'm thinking that this might involve python.
--
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/).
Reply | Threaded
Open this post in threaded view
|

Re: GGRAPH Scatterplot: Any way to "Attach label to line" via syntax?

Jon K Peck
The problem is that the label requires access to the data to determine the equation, and chart templates do not currently have access to the data. The only way I can see to automate this would be to use Python and OMS to run each regression first, perhaps using CURVEFIT for simplicity, capture the coefficients via OMS, and then generate the required GGRAPH/GPL with a label() function call with the equation from CURVEFIT.  Ugly, but the Viz engine doesn't provide access to the necessary data.


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        Bruce Weaver <[hidden email]>
To:        [hidden email]
Date:        07/24/2015 09:00 AM
Subject:        Re: [SPSSX-L] GGRAPH Scatterplot:  Any way to "Attach label to line" via syntax?
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Given that the manual Chart Editor steps I described in my first post result
in the two equations being attached to their respective lines, I assume
those equations must be stored somewhere as part of the chart, and I was
hoping to get access to them via some GPL function.  But judging from what
you and Andy have said, I am probably out of luck.

Thanks,
Bruce



ViAnn Beadle wrote
> I assume that you want to solve for equation and not just pass along a
> string. I wonder if the TRANS statement could be used to do that.
> Otherwise, I'm thinking that this might involve python.





-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/GGRAPH-Scatterplot-Any-way-to-Attach-label-to-line-via-syntax-tp5730273p5730283.html
Sent from the SPSSX Discussion mailing list archive at 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