Bar chart of means WITH counts in the labels

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

Bar chart of means WITH counts in the labels

Jim-208
I have a bar chart that presents a series of means. In the data labels, I
would like to include the counts (n=##). Is there a way to do this? Thanks.

=====================
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: Bar chart of means WITH counts in the labels

Andy W
Not sure off-hand if you can do this through the GUI, but if you have your data already aggregated to a table you can use specify the count as a label.

******************************************.
data list free / Var (A2) Mean Count (2F3.1).
begin data
X1 3.4 50
X2 5.6 60
X3 6.7 70
X4 8.2 80
end data.

GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=Var Mean Count
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
 SOURCE: s=userSource(id("graphdataset"))
 DATA: Var=col(source(s), name("Var"), unit.category())
 DATA: Count=col(source(s), name("Count"), unit.category())
 DATA: Mean=col(source(s), name("Mean"))
 GUIDE: axis(dim(1))
 GUIDE: axis(dim(2), label("Mean"))
 SCALE: cat(dim(1))
 SCALE: linear(dim(2), include(0))
 ELEMENT: interval(position(Var*Mean), shape.interior(shape.square), label(Count))
END GPL.
******************************************.

Note if you are presenting means it may be better just to plot an error bar chart around the means (so smaller counts will have a larger error bar). This is directly available through the GUI without having to aggregate the data yourself.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: Bar chart of means WITH counts in the labels

Jim-208
In reply to this post by Jim-208
Thank you for your suggestion.

I was hoping that I could set up the chart in Chart Builder, paste to syntax, and then just lightly
modify the syntax.

I think I'm getting stuck with the whole #SUMMARY and #INDEX thing in GPL. I can get the chart to
show VALIDN and I can get another chart to show MEAN. I just can't figure out how to show MEAN
with VALIDN as a data label. It seems like it would just be a few short GPL statements.

=====================
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: Bar chart of means WITH counts in the labels

Andy W
Post examples of your syntax that results in MEAN labels and results in VALIDN labels using the aggregation functions. I'm guessing the labels you want are possible directly from the aggregated summaries, but I'm not 100% sure. You may need to intermingle GPL code from both to get what you want.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: Bar chart of means WITH counts in the labels

Matt Freeman
In reply to this post by Jim-208
Jim - If I understand correctly what you are trying to do, just add another
label statement to Andy's code:

ELEMENT: interval(position(Var*Mean), shape.interior(shape.square),
label(Count), label(Mean))

This will put both Count and Mean as labels in your chart.

Matt

=====================
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: Bar chart of means WITH counts in the labels

Art Kendall
If this is a one time effort, find the counts and add them to the value labels.
Art Kendall
Social Research Consultants
On 1/24/2014 7:15 PM, Matt Freeman [via SPSSX Discussion] wrote:
Jim - If I understand correctly what you are trying to do, just add another
label statement to Andy's code:

ELEMENT: interval(position(Var*Mean), shape.interior(shape.square),
label(Count), label(Mean))

This will put both Count and Mean as labels in your chart.

Matt

=====================
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



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Bar-chart-of-means-WITH-counts-in-the-labels-tp5724069p5724135.html
To start a new topic under SPSSX Discussion, email [hidden email]
To unsubscribe from SPSSX Discussion, click here.
NAML

Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Bar chart of means WITH counts in the labels

Andy W
Good call Art. That can even be done in syntax via AGGREGATE, VALUELABELS and CONCAT command. (If you pass string variables it is the same as passing value labels.) Also note if this causes your labels (on the x-axis) to be long, you can insert "\n" and make the label go into a new line.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: Bar chart of means WITH counts in the labels

ViAnn Beadle
The OP's chart graphs the means of multiple summary variables and uses the
variable label from each variable to provide a label on the X axis. This
type of chart is known generally as a summary of separate variables. When he
uses the Chart Editor to create the chart it builds a new data matrix which
is functionally similar to the VARSTOCASES command. This works reasonable
well for the simple case but in his example he needs counts for valid cases
for each bar.

Graph algebra can create this chart but the algebra is a bit difficult to
write. Here is a simple example that creates a bar chart for the mean of
variable Y1 and Y2 and labels the bar with count of valid cases for each.
The + operator is used to concatenate the two variables:

GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=Y1 Y2
    MISSING= VARIABLEWISE REPORTMISSING=NO
   /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: Y1=col(source(s), name("Y1"))
  DATA: Y2=col(source(s), name("Y2"))
  GUIDE: axis(dim(2), label("Mean"))
  SCALE: linear(dim(2), include(0))
  ELEMENT: interval(position(summary.mean("Y1"*Y1)+("Y2"*Y2))),
   shape.interior(shape.square), label(summary.count(Y1+Y2)))
END GPL.

"Y1" is a label for variable Y1 and "Y2" is a label for Y2. You would most
likely provide something more descriptive.

So, summary.mean("Y1"*Y1) creates a bar for the mean of Y1 and places the
label "Y1" on the X axis and ("Y2"*Y2) creates a bar for the mean of Y2 and
places the label "Y2" on the X axis. The + operator creates the two bars.
The label is calculated by summary.count(Y1+Y2).


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Andy W
Sent: Saturday, January 25, 2014 6:22 AM
To: [hidden email]
Subject: Re: Bar chart of means WITH counts in the labels

Good call Art. That can even be done in syntax via AGGREGATE, VALUELABELS
and CONCAT command. (If you pass string variables it is the same as passing
value labels.) Also note if this causes your labels (on the x-axis) to be
long, you can insert "\n" and make the label go into a new line.



-----
Andy W
[hidden email]
http://andrewpwheeler.wordpress.com/
--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Bar-chart-of-means-WITH-counts
-in-the-labels-tp5724069p5724140.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: Bar chart of means WITH counts in the labels

Jim-208
In reply to this post by Jim-208
Thank you. So I now have counts in my labels. Is there a way to include
the mean value in the label as well? Here is the code I'm working with now.


GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=Q1 Q2
    MISSING= VARIABLEWISE REPORTMISSING=NO
   /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: Q1=col(source(s), name("Q1"))
  DATA: Q2=col(source(s), name("Q2"))
  COORD: rect(dim(1,2), transpose())
  GUIDE: axis(dim(2), label("Mean"))
  SCALE: linear(dim(2), include(0))
  ELEMENT: interval(position(summary.mean("Q1"*Q1)+("Q2"*Q2))),
   shape.interior(shape.square), label(summary.count(Q1+Q2)))
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: Bar chart of means WITH counts in the labels

ViAnn Beadle
Yes, you can by adding yet another label function to your ELEMENT statement
using summary.mean() function. But my question is why would you do this
since it just duplicates the mean displayed in the bar height?
-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jim
Sent: Monday, January 27, 2014 2:19 PM
To: [hidden email]
Subject: Re: Bar chart of means WITH counts in the labels

Thank you. So I now have counts in my labels. Is there a way to include
the mean value in the label as well? Here is the code I'm working with now.


GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=Q1 Q2
    MISSING= VARIABLEWISE REPORTMISSING=NO
   /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: Q1=col(source(s), name("Q1"))
  DATA: Q2=col(source(s), name("Q2"))
  COORD: rect(dim(1,2), transpose())
  GUIDE: axis(dim(2), label("Mean"))
  SCALE: linear(dim(2), include(0))
  ELEMENT: interval(position(summary.mean("Q1"*Q1)+("Q2"*Q2))),
   shape.interior(shape.square), label(summary.count(Q1+Q2)))
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

=====================
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: Bar chart of means WITH counts in the labels

Jim-208
In reply to this post by Jim-208
Thanks for your help. Much appreciated. This was my final code. Having
both values was my bosses way of torturing me. :-)


GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=Q1 Q2
    MISSING= VARIABLEWISE REPORTMISSING=NO
   /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: Q1=col(source(s), name("Q1"))
  DATA: Q2=col(source(s), name("Q2"))
  COORD: rect(dim(1,2), transpose())
  GUIDE: axis(dim(2), label("Mean"))
  SCALE: linear(dim(2), include(0))
  ELEMENT: interval(position(summary.mean("Q1"*Q1)+("Q2"*Q2))),
   shape.interior(shape.square), label(summary.count(Q1+Q2)))
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