I would like to set up a chart with one horizontal line for a number of individuals with one starting point and another point at the end, the kind of chart often used to describe time to some event. Addition of symbols for different outcomes - death, censoring,... - at the end would also be nice, possibly also to have lines colored differently depending on outcome. My attempts so far do not work. The closest is a chart with differently colored lines for each indvidual, however, keeping lines the same color and addition of endpoint symbols have not worked.
The syntax run so far (where status is meant to be used for the end symbol): DATA LIST FREE(",")/nr(F1) time(F2) status(F1). BEGIN DATA 1,0 ,,1,12,1,2,3,,2,15,2,3,2,,3,14,1 END DATA. DATASET NAME ttevent WINDOW=FRONT. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=time nr MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: time=col(source(s), name("time")) DATA: nr=col(source(s), name("nr"), unit.category()) DATA: nr1=col(source(s), name("nr"), unit.category()) GUIDE: axis(dim(1), label("time")) GUIDE: axis(dim(2), label("nr")) GUIDE: legend(aesthetic(aesthetic.color.interior), label("nr")) GUIDE: text.title(label("Multiple Line of nr by time by nr")) ELEMENT: line(position(time*nr), color.interior(nr1), missing.wings()) END GPL. My starting point with data in a long format and line plots might not be the best way at all. So, any suggestions as to make such lines the same color and to add symbols at the end points? It should be quite easy, shouldn't it? Robert ===================== 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
Robert Lundqvist
|
Here is an example, you may aggregate and color the whole line as well per
the end status. ***********************************. DO IF NOT MISSING(status). COMPUTE t2 = time. COMPUTE nr2 = nr. END IF. FORMATS t2 nr2 (F2.0). EXECUTE. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=time nr status t2 nr2 MISSING=VARIABLEWISE /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: time=col(source(s), name("time")) DATA: t2=col(source(s), name("t2")) DATA: nr2=col(source(s), name("nr2")) DATA: nr=col(source(s), name("nr")) DATA: nr1=col(source(s), name("nr"), unit.category()) DATA: status=col(source(s), name("status"), unit.category()) GUIDE: axis(dim(1), label("time")) GUIDE: axis(dim(2), label("nr")) GUIDE: legend(aesthetic(aesthetic.shape), label("Status")) ELEMENT: line(position(time*nr), split(nr1)) ELEMENT: point(position(t2*nr2), shape(status), size(size."12")) END GPL. ***********************************. Also see here for an attempt to stack lines like this for some other data I was working with. It didn't turn out as cool as I hoped though, pretty mess for my stuff to viz. any obvious patterns. https://andrewpwheeler.com/2014/10/02/stacking-intervals/ ----- Andy W [hidden email] http://andrewpwheeler.wordpress.com/ -- Sent from: http://spssx-discussion.1045642.n5.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 |
In reply to this post by Robert L
Here is another version using the demo dataset.
To color the line according to the outcome, the outcome needs to be known in when drawing the line. To plot the outcome marker you need a variable which corresponds to the last point only. Note the MISSING = VARIABLEWISE subcommand. For some reason coloring of the marker is lost when I try to control the shapes. If not specified (i.e. use standard SPSS order) colors follow the line coloring. Beware that the variable status is altered -- maybe use a copy... My quite spacious layout allows for deleting/adding a line without too much errors. GPL is picky... HTH, PR **************. DATA LIST FREE(",")/ nr(F1) time(F2) status(F1). BEGIN DATA 1,0 ,,1,12,1,2,3,,2,15,2,3,2,,3,14,1 END DATA. DATASET NAME ttevent WINDOW=FRONT. SORT CASES nr (A) time (D). IF NOT MISSING(status) t2 = time. IF MISSING(status) status = LAG(status). GGRAPH /GRAPHDATASET NAME = "graphdataset" VARIABLES = time t2 nr status MISSING = VARIABLEWISE REPORTMISSING = NO /GRAPHSPEC SOURCE = INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: time = col(source(s), name("time")) DATA: t2 = col(source(s), name("t2")) DATA: nr = col(source(s), name("nr"), unit.category()) DATA: status = col(source(s), name("status"), unit.category()) GUIDE: text.title(label("Multiple Line of nr by time by nr")) GUIDE: axis(dim(1) ,label("time") ) GUIDE: axis(dim(2) ,label("nr") ) COMMENT: if you want to enable shape mapping, enter a ':' after 'SCALE' SCALE cat(aesthetic(aesthetic.shape) ,map(("1", shape.square) ,("2", shape.triangle) ) ) SCALE: cat(aesthetic(aesthetic.color.interior) ,map(("1", color.red) ,("2", color.green) ) ) SCALE: cat(aesthetic(aesthetic.color.exterior) ,map(("1", color.red) ,("2", color.green) ) ) ELEMENT: line(position(time*nr) ,color.interior(status) ,missing.wings() ,split(nr) ) ELEMENT: point(position(t2*nr) ,shape(status) ,size(size."12") ,color.interior(status) ,color.exterior(status) ) END GPL. I would like to set up a chart with one horizontal line for a number of individuals with one starting point and another point at the end, the kind of chart often used to describe time to some event. Addition of symbols for different outcomes - death, censoring,... - at the end would also be nice, possibly also to have lines colored differently depending on outcome. My attempts so far do not work. The closest is a chart with differently colored lines for each indvidual, however, keeping lines the same color and addition of endpoint symbols have not worked. ... So, any suggestions as to make such lines the same color and to add symbols at the end points? It should be quite easy, shouldn't it? ... -- Sent from: http://spssx-discussion.1045642.n5.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 |
Free forum by Nabble | Edit this page |