One of the best known charts is a simple bar chart containing frequencies or percentages. The easiest way to run it in SPSS is the FREQUENCIES command. This tutorial walks you through some options. We'll use freelancers.sav throughout, part of which is shown below.
Option 1: FREQUENCIES
In most cases, a simple FREQUENCIES command is our best option because it takes multiple variables in one go. Its syntax -shown below- is so simple that just typing it is probably faster than messing around with the menu.
frequencies sector_2010 to sector_2014
Result - Basic
Unsurprisingly, we created the desired bar charts but -like most SPSS charts- they look awful. A great way to fix that is using an SPSS chart template. Just one template is sufficient for having pretty bar charts for once and for all.
A chart template can also transpose (“put on its side”) our chart, which works much better for bar charts than SPSS’ default orientation. One of the charts that resulted from the template we built is shown below.
Result - Chart Template
Sorting Categories and Percentages
A nice -albeit little known- option is sorting the categories. If we transpose our chart, we can sort our bars by descending frequency by specifying /FORMAT NOTABLE AFREQ (use DFREQ for untransposed charts).
Second, we can have percentages instead of frequencies by using /BARCHART PERCENT as shown in the syntax below.
Sorted Bar Charts with Percentages Syntax
/format notable afreq
Note: the %-sign is missing from our chart but we can fix this by modifying our chart template.
Option 2: GRAPH
When we run bar charts with FREQUENCIES, the variable labels of the variables involved are used as chart titles. If we want custom titles instead, we're perhaps better off by using GRAPH.Alternatively, set the desired chart titles as new variable labels. Preceding this with TEMPORARY restores the old labels. Since its syntax is a bit more difficult, we'll generate it from the menu as shown below.
/BAR(SIMPLE)=PCT BY sector_2010
/TITLE='All Respondents | n = 40'.
Note: unfortunately, GRAPH takes only one variable at the time. However, we can remove the line breaks from the syntax and copy-paste-edit it a couple of times for a handful of variables. For running charts or tables over many variables, see SPSS with Python - Looping over Scatterplots.
Second, GRAPH does not allow us to sort our categories but a chart template can fix that.
SPSS Bar Charts - Chart Sizes
One issue with all SPSS charts is that their sizes are fixed in pixels. However, a bar chart for many categories needs more space than a chart for few categories. In fact, categories may disappear altogether if they don't fit into the chart anymore. SPSS does not offer a solution for this other than “stretching” each chart manually in the output viewer. For a better solution, see SPSS - Set Chart Sizes Tool.
With respect to the layout of reports, we prefer having the heights (rather than the widths) of our charts depend on the amount of content they contain. This is yet another good reason for always transposing our bar charts.
In most cases, typing a simple FREQUENCIES command is by far the best option for creating bar charts. GRAPH as pasted from
As with most charts, is better avoided since it's way more complicated and results in the exact same chart as the aforementioned options.
Bar Charts - FREQUENCIES Versus GRAPH
The table below quickly summarizes the differences between the two options we discussed in this tutorial.
|Category sorting||Yes||Only with chart template|
|Percent sign||Only with chart template||Yes|
THIS TUTORIAL HAS 13 COMMENTS:
By Ruben Geert van den Berg on April 12th, 2021
Would you like one bar showing the frequency for each answer over the 3 variables?
Then I think you must restructure you data and stack the 3 variables on top of each other.
This is usually done with VARSTOCASES but that's pretty tedious.
There's a tiny hack for achieving the same results (less tedious) without VARSTOCASES that I covered in Clustered Bar Chart over Multiple Variables.
In any case, I don't think there's any quick and simple option for getting it done but correct me if you do find one.
Hope that helps!
By Kurt on April 29th, 2021
thank you for the recent reply. I sorted it out via a table and then pulling it into excel and make a graph there :-). I know, cheating.
I have another question:
Is it possible in the syntax to indicate that I want to see the numbers and percent? And maybe also automatically indicate the total number of cases used for the graph?
Like I have this syntax :
/GRAPHDATASET NAME="graphdataset" VARIABLES=Age COUNT()[name="COUNT"] MISSING=LISTWISE
/COLORCYCLE COLOR1(17,146,232), COLOR2(225,188,29), COLOR3(237,75,75), COLOR4(95,195,56),
COLOR5(87,4,8), COLOR6(171,73,243), COLOR7(0,45,156), COLOR8(238,83,139), COLOR9(178,134,0),
COLOR10(0,157,154), COLOR11(1,39,73), COLOR12(138,56,0), COLOR13(254,130,180),
COLOR14(236,230,208), COLOR15(69,70,71), COLOR16(92,202,136), COLOR17(208,83,52),
COLOR18(204,127,228), COLOR19(225,188,29), COLOR20(237,75,75), COLOR21(28,205,205),
COLOR22(92,113,72), COLOR23(225,139,14), COLOR24(9,38,114), COLOR25(90,100,94), COLOR26(155,0,0),
COLOR27(207,172,227), COLOR28(150,145,145), COLOR29(63,235,124), COLOR30(105,41,196)
/FRAME OUTER=NO INNER=NO
/GRIDLINES XAXIS=NO YAXIS=YES
DATA: Age=col(source(s), name("Age"), unit.category())
DATA: COUNT=col(source(s), name("COUNT"))
GUIDE: axis(dim(1), null())
GUIDE: legend(aesthetic(aesthetic.color.interior), label("Age"))
GUIDE: text.title(label("How old are you?"))
SCALE: linear(dim(1), dataMinimum(), dataMaximum())
ELEMENT: interval.stack(position(summary.percent(COUNT))), color.interior(Age))
So it would be great if I could automatically display the number per age bracket and the corresponding percentage and if possible also the total of all the age brackets. I can do it by manually amending the graph, but it would be nice if it would be in the syntax already.
Thanks in advance for the reply.
By Ruben Geert van den Berg on April 30th, 2021
Some stuff like that can be done with syntax indeed but it can be hard and may sometimes require restructuring your data.
I've done things like these in the (far) past and I may look into it again at some point again but it's not on the top of my list.
A colleague who covers situations like these on his website is Andrew ("Andy") Wheeler. Perhaps look up his website and/or contact him directly?
P.s. if you get it done, you can speed up and automate some of the stuff with Python -highly recommended for any heavy SPSS user!