Graphing/GLP legend help

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

Graphing/GLP legend help

Kylie

Hi,

 

I am trying to construct a line graph of individual subjects’ changes over time, where the colour of each subject is according to subgroup. I have data in the long format – two rows per subject (pre and post). I wish to have Time (pre/post) on the x-axis, the outcome (‘Cornell’ in the code below) on the y-axis and a separate line per subject (‘Resident’ in the code below). So far this is straight forward. Additionally, I wish to colour the lines by group (‘InterventionGroup’ in the code below), and this is where I am stuck.

 

Here is the default GPL for the basic per-subject graph. I can’t figure out how to incorporate the group colour legend, while still drawing one line per subject.

 

GGRAPH

  /GRAPHDATASET NAME="graphdataset" VARIABLES=Time Cornell Resident

  /GRAPHSPEC SOURCE=INLINE.

BEGIN GPL

  SOURCE: s=userSource(id("graphdataset"))

  DATA: Time=col(source(s), name("Time"), unit.category())

  DATA: Cornell=col(source(s), name("Cornell"))

  DATA: Resident=col(source(s), name("Resident"), unit.category())

  GUIDE: axis(dim(1), label("Time"))

  GUIDE: axis(dim(2), label("Cornells"))

  GUIDE: legend(aesthetic(aesthetic.color.interior), label("Resident"))

  SCALE: linear(dim(2), include(0))

  ELEMENT: line(position(Time*Cornell), color.interior(Resident), missing.wings())

END GPL.

 

 

Alternatively, I can get almost-there using the Graphboard Chooser. Here, I included subject as a ‘size’ legend and Group as a ‘colour’ legend, hoping to be able to edit the sizes afterwards to be indistinguishable from each other. However, I can’t seem to edit those settings after the graph is created, so my lines are the correct colour, but range from thin to thick which I’d like to avoid.

 

GGRAPH

  /GRAPHDATASET NAME="graphdataset"

    VARIABLES=Resident[LEVEL=nominal] Time[LEVEL=nominal] Cornell[LEVEL=scale] IterventionGroup[LEVEL=nominal]

    MISSING=LISTWISE REPORTMISSING=NO

  /GRAPHSPEC SOURCE=VIZTEMPLATE(NAME="Line"[LOCATION=LOCAL]

    MAPPING( "size"="Resident"[DATASET="graphdataset"] "color"="InterventionGroup"[DATASET="graphdataset"] "x"="Time"[DATASET="graphdataset"] "y"="Cornell"[DATASET="graphdataset"] "Summary"="mode"))

    VIZSTYLESHEET="Traditional"[LOCATION=LOCAL]

    LABEL='LINE: Cornell-Time'

    DEFAULTTEMPLATE=NO.

 

 

Any suggestions?

 

Thanks,

Kylie.

===================== 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: Graphing/GLP legend help

Andy W
In the ELEMENT statement you need to split by resident and color by InterventionGroup. Example below.

***************************************.
SET SEED 10.
INPUT PROGRAM.
LOOP #i = 1 TO 2.
  LOOP #j = 1 TO 50.
    COMPUTE Time = #i.
    COMPUTE Resident = #j.
    END CASE.
  END LOOP.
END LOOP.
END FILE.
END INPUT PROGRAM.
DATASET NAME sim.
COMPUTE InterventionGroup = (Resident > 25).
SORT CASES BY Resident Time.
DO IF Time = 1.
  COMPUTE Cornell = RV.NORMAL(0,1).
ELSE.
  COMPUTE Cornell = 0.5*LAG(Cornell) + 0.5*InterventionGroup + RV.NORMAL(0,0.2).
END IF.
FORMATS InterventionGroup Time (F1.0).


GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=Time Cornell Resident InterventionGroup
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: Time=col(source(s), name("Time"), unit.category())
  DATA: Cornell=col(source(s), name("Cornell"))
  DATA: Resident=col(source(s), name("Resident"), unit.category())
  DATA: InterventionGroup=col(source(s), name("InterventionGroup"), unit.category())
  GUIDE: axis(dim(1), label("Time"))
  GUIDE: axis(dim(2), label("Cornells"))
  GUIDE: legend(aesthetic(aesthetic.color.interior), label("InterventionGroup"))
  SCALE: linear(dim(2), include(0))
  ELEMENT: line(position(Time*Cornell), split(Resident), color.interior(InterventionGroup), missing.wings())
END GPL.
***************************************.

I actually wrote a whole paper about why I don't like those types of slopegraphs for pre-post data, see "A Critique of Slopegraphs", http://papers.ssrn.com/sol3/papers.cfm?abstract_id=2410875. Scatterplots are frequently a better graphic visualization.

*Scatterplots are better!.
CASESTOVARS /ID = Resident /INDEX = Time.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=Cornell.1[name="Cornell_1"]
    Cornell.2[name="Cornell_2"] InterventionGroup MISSING=LISTWISE REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: Cornell_1=col(source(s), name("Cornell_1"))
  DATA: Cornell_2=col(source(s), name("Cornell_2"))
  DATA: InterventionGroup=col(source(s), name("InterventionGroup"), unit.category())
  GUIDE: axis(dim(1), label("Cornell.1"))
  GUIDE: axis(dim(2), label("Cornell.2"))
  GUIDE: legend(aesthetic(aesthetic.color.exterior), label("InterventionGroup"))
  ELEMENT: point(position(Cornell_1*Cornell_2), color.exterior(InterventionGroup))
END GPL.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/