1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
* Suppose you have 2 categorical variables (cat1 and cat2).
* You want to produce a clustered bars IGRAPH where the 
* percentages are based on the total population of each set of cluster.
* rlevesque@videotron.ca.

* Define dummy data file for illustration purposes.
NEW file.
SET SEED=9864315.
INPUT PROGRAM.
LOOP id=1 TO 100.
	COMPUTE cat1=RND(UNIFORM(5)+.5).
	COMPUTE cat2=RND(UNIFORM(4)+.5).
	END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.
EXECUTE.

SORT CASES BY cat1 cat2.
SAVE OUTFILE='C:\\temp\\mydata.sav'.

AGGREGATE OUTFILE='C:\\temp\\temp1.sav'
  /BREAK=cat1
  /id = N(id)
  /n_cat1=N.

GET FILE='C:\\temp\\mydata.sav'

AGGREGATE OUTFILE='C:\\temp\\temp2.sav'
  /BREAK=cat1 cat2
  /id = N(id)
  /n_cat12=N.

MATCH FILES FILE='C:\\temp\\mydata.sav'
	/TABLE='C:\\temp\\temp1.sav'
	/BY cat1.

MATCH FILES FILE=*
 	/TABLE='C:\\temp\\temp2.sav'
	/BY cat1 cat2.
COMPUTE pc=100*n_cat12/n_cat1.
FORMATS pc (PCT5.1).
EXECUTE.

IGRAPH /VIEWNAME='Bar Chart' /X1 = VAR(cat1) TYPE = SCALE /Y = VAR(pc) TYPE =
  SCALE /STYLE = VAR(cat2) CLUSTER /COORDINATE = VERTICAL  /X1LENGTH=3.0
 /YLENGTH=3.0 /X2LENGTH=3.0 /CHARTLOOK='NONE' /CATORDER VAR(cat2) (ASCENDING
  VALUES OMITEMPTY) /BAR(FIRST) KEY=ON SHAPE = RECTANGLE BASELINE = AUTO.
Related pages

...