Display absolute Frequencies in Pie Chart by Script

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

g.giesinger
Posts: 1
Joined: Wed Jun 10, 2015 8:11 am

Display absolute Frequencies in Pie Chart by Script

Postby g.giesinger » Wed Jun 10, 2015 8:22 am

Hi there,

instead of klicking in the Chart Editor (= Show Data Labels - Properties - Data Value Labels – Count) I want to display absolute frequencies in pie charts by script. Is this possible? If yes, how?

I use PASW Statistics 18.

Thanks in advance.

Best regards

Gert
JonPedersen
Posts: 117
Joined: Wed May 25, 2011 7:07 am
Contact:

Re: Display absolute Frequencies in Pie Chart by Script

Postby JonPedersen » Wed Jul 08, 2015 12:06 pm

Hi,
See the code below:

Code: Select all

* some data to play with.
*.
data list FREE /burden cat.
begin data
23,1
45,2
110,3
end data.
variable labels cat "Categorical variable".
value labels cat 1 "whatever 1" 2 "Wherever 2" 3 "Whoever 3".
weight by burden.  
* Make the graph.

GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=cat COUNT()[name="COUNT"] MISSING=LISTWISE 
    REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: cat=col(source(s), name("cat"), unit.category())
  DATA: COUNT=col(source(s), name("COUNT"))
  COORD: polar.theta(startAngle(0))
  GUIDE: axis(dim(1), null())
  GUIDE: legend(aesthetic(aesthetic.color.interior), label("Categorical variable"))
  GUIDE: text.title(label("This is the title"))
  GUIDE: text.footnote(label("This is a footnote"))
  SCALE: linear(dim(1), dataMinimum(), dataMaximum())
  SCALE: cat(aesthetic(aesthetic.color.interior), include("1.00", "2.00", "3.00"))
  ELEMENT:  interval.stack(position(summary.percent(summary.percent(COUNT,
    base.all(acrossPanels())))), color.interior(cat), label(COUNT),label(cat)),label(summary.percent(COUNT,
    base.all(acrossPanels()))))
END GPL.
The important part is the three label parameters in the ELEMENT part. The first, label(COUNT), gives you the count, the second the label and the third the percentage.
They can be included, omitted, or rearranged as desired.
If you dont want the legend, then replice the GUIDE statement with the legend with

Code: Select all

GUIDE: legend(aesthetic(aesthetic.color.interior), null())
hth
Jon
RubenGeert
Posts: 100
Joined: Mon May 19, 2014 6:06 am

Re: Display absolute Frequencies in Pie Chart by Script

Postby RubenGeert » Wed Jul 08, 2015 3:51 pm

Alternatively, add these frequencies with "data labels mode" and style your chart a bit more manually and then save these styles as a chart template. An excellent tutorial that shows how to do so is http://www.spss-tutorials.com/spss-chart-templates/. You probably don't want to stick with SPSS' super ugly default chart styles anyway.

After doing so, you can create a million similarly styled charts -with absolute frequencies that is- by running something like

Code: Select all

set ctemplate 'd:/temp/piechart.sgt'.

GRAPH  /PIE=COUNT BY v1.
where "piechart.sgt" denotes the chart template you created. After running all pie charts, switch off the chart template by

Code: Select all

set ctemplate none.
JonPedersen
Posts: 117
Joined: Wed May 25, 2011 7:07 am
Contact:

Re: Display absolute Frequencies in Pie Chart by Script

Postby JonPedersen » Thu Jul 09, 2015 8:53 am

That is probably true, especially the part about SPSS's horrible default graphs. And Ruben's tutorial is quite good.
jon

Who is online

Users browsing this forum: No registered users and 2 guests

cron