Plotting Error as Dashed Lines

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

Plotting Error as Dashed Lines

JSB
I was able to figure out the syntax for custom error bars, but still have a few issues I couldn't decipher. Any guidance would be appreciated:

1. The scatterplot uses "shape.ibeam" for the error bars, but for some reason they still lack the T shape. Is there a way to get the T shaped errors?
2. When I tried the shaded area for error bars (Andy, I got that part from your blog), the shaded regions are overlapping, whereas the error bars in the scatterplot version do not overlap. I thought perhaps my syntax is somehow misspecified.
3. My real goal is to have a dashed line for the error region instead of a shaded area, but I couldn't find the syntax for that. Here is an example with dots, instead of dashes: https://tinyurl.com/y8p3slag

As a side note, the help resources from SPSS are very lacking. SAS has an excellent guide online on every piece of statement which enabled me to run mixed models in a day. For SPSS, I can't even find the full list of syntax rules for the ELEMENT statement online.

Here is the data+syntax:

DATA LIST LIST
/ Treatment(A8)    Time    Outcome    CI_min    CI_max.
BEGIN DATA
Treat1    1.00    5.41    5.24    5.57
Treat1    2.00    5.40    5.24    5.56
Treat1    3.00    5.39    5.23    5.56
Treat1    4.00    5.39    5.22    5.55
Treat1    5.00    5.38    5.22    5.54
Treat1    6.00    5.37    5.21    5.54
Treat1    7.00    5.37    5.21    5.53
Treat1    8.00    5.36    5.20    5.53
Treat1    9.00    5.36    5.19    5.52
Treat1    10.00    5.35    5.19    5.51
Treat2    1.00    5.07    4.94    5.21
Treat2    2.00    5.07    4.93    5.20
Treat2    3.00    5.06    4.93    5.20
Treat2    4.00    5.06    4.92    5.19
Treat2    5.00    5.05    4.91    5.19
Treat2    6.00    5.04    4.91    5.18
Treat2    7.00    5.04    4.90    5.17
Treat2    8.00    5.03    4.89    5.17
Treat2    9.00    5.03    4.89    5.16
Treat2    10.00    5.02    4.88    5.16
END DATA.

*Whisker bars on scatterplot.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=Time Outcome Treatment CI_min CI_max MISSING=LISTWISE
    REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: Time=col(source(s), name("Time"))
  DATA: Outcome=col(source(s), name("Outcome"))
  DATA: Treatment=col(source(s), name("Treatment"), unit.category())
  DATA: CI_min=col(source(s), name("CI_min"))
  DATA: CI_max=col(source(s), name("CI_max"))
  GUIDE: axis(dim(1), label("Time"))
  GUIDE: axis(dim(2), label("Outcome"))
  GUIDE: legend(aesthetic(aesthetic.color.interior), label("Treatment"))
  ELEMENT: point(position(Time*Outcome), color.interior(Treatment)), shape(shape.plus)
  ELEMENT: interval(position(region.spread.range(Time*(CI_min+CI_max))), shape.interior(shape.ibeam), color.interior(Treatment))
END GPL.

*Shaded error on lineplot.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=Time Outcome Treatment CI_min CI_max MISSING=LISTWISE
    REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: Time=col(source(s), name("Time"))
  DATA: Outcome=col(source(s), name("Outcome"))
  DATA: Treatment=col(source(s), name("Treatment"), unit.category())
  DATA: CI_min=col(source(s), name("CI_min"))
  DATA: CI_max=col(source(s), name("CI_max"))
  GUIDE: axis(dim(1), label("Time"))
  GUIDE: axis(dim(2), label("Outcome"))
  GUIDE: legend(aesthetic(aesthetic.color.interior), label("Treatment"))
  ELEMENT: line(position(Time*Outcome), color.interior(Treatment), missing.wings())
  ELEMENT: area.difference(position(region.spread.range(Time*(CI_min+CI_max))), color.interior(color.lightgrey), transparency.interior(transparency."0.7"))
END GPL.

===================== 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
JSB
Reply | Threaded
Open this post in threaded view
|

Re: Plotting Error as Dashed Lines

JSB
The first ggraph was had an error. Here is the right version:

*Whisker bars on scatterplot.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=Time Outcome Treatment CI_min CI_max MISSING=LISTWISE
    REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: Time=col(source(s), name("Time"))
  DATA: Outcome=col(source(s), name("Outcome"))
  DATA: Treatment=col(source(s), name("Treatment"), unit.category())
  DATA: CI_min=col(source(s), name("CI_min"))
  DATA: CI_max=col(source(s), name("CI_max"))
  GUIDE: axis(dim(1), label("Time"))
  GUIDE: axis(dim(2), label("Outcome"))
  GUIDE: legend(aesthetic(aesthetic.color.interior), label("Treatment"))
  ELEMENT: point(position(Time*Outcome), color.interior(Treatment))
  ELEMENT: interval(position(region.spread.range(Time*(CI_min+CI_max))), shape.interior(shape.ibeam), color.interior(Treatment))
END GPL.

On Thu, Oct 19, 2017 at 10:12 PM, Brown Vincent <[hidden email]> wrote:
I was able to figure out the syntax for custom error bars, but still have a few issues I couldn't decipher. Any guidance would be appreciated:

1. The scatterplot uses "shape.ibeam" for the error bars, but for some reason they still lack the T shape. Is there a way to get the T shaped errors?
2. When I tried the shaded area for error bars (Andy, I got that part from your blog), the shaded regions are overlapping, whereas the error bars in the scatterplot version do not overlap. I thought perhaps my syntax is somehow misspecified.
3. My real goal is to have a dashed line for the error region instead of a shaded area, but I couldn't find the syntax for that. Here is an example with dots, instead of dashes: https://tinyurl.com/y8p3slag

As a side note, the help resources from SPSS are very lacking. SAS has an excellent guide online on every piece of statement which enabled me to run mixed models in a day. For SPSS, I can't even find the full list of syntax rules for the ELEMENT statement online.

Here is the data+syntax:

DATA LIST LIST
/ Treatment(A8)    Time    Outcome    CI_min    CI_max.
BEGIN DATA
Treat1    1.00    5.41    5.24    5.57
Treat1    2.00    5.40    5.24    5.56
Treat1    3.00    5.39    5.23    5.56
Treat1    4.00    5.39    5.22    5.55
Treat1    5.00    5.38    5.22    5.54
Treat1    6.00    5.37    5.21    5.54
Treat1    7.00    5.37    5.21    5.53
Treat1    8.00    5.36    5.20    5.53
Treat1    9.00    5.36    5.19    5.52
Treat1    10.00    5.35    5.19    5.51
Treat2    1.00    5.07    4.94    5.21
Treat2    2.00    5.07    4.93    5.20
Treat2    3.00    5.06    4.93    5.20
Treat2    4.00    5.06    4.92    5.19
Treat2    5.00    5.05    4.91    5.19
Treat2    6.00    5.04    4.91    5.18
Treat2    7.00    5.04    4.90    5.17
Treat2    8.00    5.03    4.89    5.17
Treat2    9.00    5.03    4.89    5.16
Treat2    10.00    5.02    4.88    5.16
END DATA.

*Whisker bars on scatterplot.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=Time Outcome Treatment CI_min CI_max MISSING=LISTWISE
    REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: Time=col(source(s), name("Time"))
  DATA: Outcome=col(source(s), name("Outcome"))
  DATA: Treatment=col(source(s), name("Treatment"), unit.category())
  DATA: CI_min=col(source(s), name("CI_min"))
  DATA: CI_max=col(source(s), name("CI_max"))
  GUIDE: axis(dim(1), label("Time"))
  GUIDE: axis(dim(2), label("Outcome"))
  GUIDE: legend(aesthetic(aesthetic.color.interior), label("Treatment"))
  ELEMENT: point(position(Time*Outcome), color.interior(Treatment)), shape(shape.plus)
  ELEMENT: interval(position(region.spread.range(Time*(CI_min+CI_max))), shape.interior(shape.ibeam), color.interior(Treatment))
END GPL.

*Shaded error on lineplot.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=Time Outcome Treatment CI_min CI_max MISSING=LISTWISE
    REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: Time=col(source(s), name("Time"))
  DATA: Outcome=col(source(s), name("Outcome"))
  DATA: Treatment=col(source(s), name("Treatment"), unit.category())
  DATA: CI_min=col(source(s), name("CI_min"))
  DATA: CI_max=col(source(s), name("CI_max"))
  GUIDE: axis(dim(1), label("Time"))
  GUIDE: axis(dim(2), label("Outcome"))
  GUIDE: legend(aesthetic(aesthetic.color.interior), label("Treatment"))
  ELEMENT: line(position(Time*Outcome), color.interior(Treatment), missing.wings())
  ELEMENT: area.difference(position(region.spread.range(Time*(CI_min+CI_max))), color.interior(color.lightgrey), transparency.interior(transparency."0.7"))
END GPL.


===================== 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: Plotting Error as Dashed Lines

Andy W
Your right on the first one that it should show the whisker bars. On my V25
if I change the element to "edge" from "interval" though I get the whiskers.
(Note I much prefer the single lines, the whiskers draw too much attention
to the ends of the errors, and the width is distracting from where the
measurement is.)

***********************************.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=Time Outcome Treatment CI_min
CI_max MISSING=LISTWISE
    REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: Time=col(source(s), name("Time"))
  DATA: Outcome=col(source(s), name("Outcome"))
  DATA: Treatment=col(source(s), name("Treatment"), unit.category())
  DATA: CI_min=col(source(s), name("CI_min"))
  DATA: CI_max=col(source(s), name("CI_max"))
  GUIDE: axis(dim(1), label("Time"))
  GUIDE: axis(dim(2), label("Outcome"))
  GUIDE: legend(aesthetic(aesthetic.color.interior), label("Treatment"))
  ELEMENT: point(position(Time*Outcome), color.interior(Treatment))
  ELEMENT: edge(position(region.spread.range(Time*(CI_min+CI_max))),
shape.interior(shape.ibeam), color.interior(Treatment),
                size(size."1"))
END GPL.
****************************************************.

For the error areas you would need to reshape your data from long to wide.
Or as an alternative you could use the polygon areas, in this example the
travelling salesman link type work. (My experiments with the alpha hull do
not work, and the concave hull do not follow the lines exactly.) I add the
end points on as well to show how the areas follow the CI ends exactly.

****************************************************.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=Time Outcome Treatment CI_min
CI_max MISSING=LISTWISE
    REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: Time=col(source(s), name("Time"))
  DATA: Outcome=col(source(s), name("Outcome"))
  DATA: Treatment=col(source(s), name("Treatment"), unit.category())
  DATA: CI_min=col(source(s), name("CI_min"))
  DATA: CI_max=col(source(s), name("CI_max"))
  GUIDE: axis(dim(1), label("Time"))
  GUIDE: axis(dim(2), label("Outcome"))
  GUIDE: legend(aesthetic(aesthetic.color.interior), label("Treatment"))
  ELEMENT: polygon(position(link.tsp(Time*(CI_min+CI_max))),
color.interior(Treatment),
           transparency.interior(transparency."0.7"),
transparency.exterior(transparency."1"))
  ELEMENT: point(position(region.spread.range(Time*(CI_min+CI_max))),
color.interior(Treatment),
           transparency.interior(transparency."0.7"), shape(shape.square))
  ELEMENT: line(position(Time*Outcome), color.interior(Treatment),
missing.wings())
END GPL.
****************************************************.

See
https://andrewpwheeler.wordpress.com/2016/03/08/on-overlapping-error-bars-in-charts/
for related discussion/examples.



-----
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
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/