SPSS TUTORIALS BASICS ANOVA REGRESSION FACTOR CORRELATION

# Creating Bar Charts with Means by Category

One of the most common research questions is do different groups have different mean scores on some variable? This question is best answered in 3 steps:

1. create a table showing mean scores per group -you'll probably want to include the frequencies and standard deviations as well;
2. create a chart showing mean scores per group;
3. run some statistical test -ANOVA in this case. However, this is only meaningful if your data are (roughly) a simple random sample from your target population.

We'll show the first 2 steps using an employee survey whose data are in bank-clean.sav. The screenshot below shows what these data basically look like.

## Creating a Means Table

For creating a table showing means per category, we could mess around with Analyze Compare Means Means but its not worth the effort as the syntax is as simple as it gets. So let's just run it and inspect the result.

*Create table with mean ratings by job type.

means q1 by jtype
/cells count mean stddev.

Note that you could easily add more statistics to the CELLS subcommand such as

## Result

Basically, our table tells us that the mean employee care ratings increase with higher job levels except for “upper management”. A proper descriptives table -always recommended- gives nicely detailed information. However, it's not very visual. So let's now run our chart.

## SPSS Bar Chart Menu & Dialogs

As a rule of thumb, I create all charts from Graphs Legacy Dialogs and avoid the Chart Builder whenever I can -which is pretty much always unless I need a stacked bar chart with percentages.

In the dialog shown below, selecting Other statistic... enables you to enter a dependent variable;

## Basic Bar Chart Means by Category Syntax

*Bar chart means by category syntax.

GRAPH
/BAR(SIMPLE)=MEAN(q1) BY jtype
/TITLE='Mean Employee Care Rating by Job Type'
/SUBTITLE='N = 423'.

## Result

We now have our basic chart but it doesn't look too good.From SPSS version 25 onwards, it will look somewhat better. However, see New Charts in SPSS 25 - How Good Are They Really? Yet. We'll fix this by setting a chart template.

Note that a chart template can also sort this bar chart -for instance by descending means- but we'll skip that for now.

## Bar Chart Means by Category Syntax II

*Set chart template (make sure the .sgt file is in default folder as shown by SHOW DIR.).

set ctemplate "bar-chart-means-trans-720-1.sgt".

*Rerun chart with template set.

GRAPH
/BAR(SIMPLE)=MEAN(q1) BY jtype
/TITLE='Mean Employee Care Rating by Job Type'
/SUBTITLE='N = 423'.

## Result

Right, so that's about it. If you need a couple of similar charts, you could copy-paste-edit the last GRAPH command (no need to repeat the other commands). If you need many similar charts, you could loop over the GRAPH command with Python for SPSS.

If you're going to run other types of charts, don't forget to set a different chart template. Or switch if off altogether by running set ctemplate none.

# Tell us what you think!

*Required field. Your comment will show up after approval from a moderator.

# THIS TUTORIAL HAS 12 COMMENTS:

• ### By David Marso on July 11th, 2018

"If you need many similar charts, you could loop over the GRAPH command with Python."
Or not to be heretical old fashioned or obstinate a simple macro would suffice. Why are people so damned obsessed with python?

• ### By Ruben Geert van den Berg on July 12th, 2018

Just writing out all syntax manually suffices too.

But -just like SPSS macros- it's just hopelessly inefficient.

For one thing, macros know nothing whatsoever about either your dictionary or your data values. They can't even look up a range of variable names.

Python does this -and many other things that macros can't- with a mere handful of clean and readable code.

Perhaps you should give it a try some time.

• ### By Arsh on January 11th, 2019

Bar charts are great. Great work showing how to make bar charts with means by category.

• ### By Ruben Geert van den Berg on January 11th, 2019

Hi Arsh, thanks for the compliment!

You might like SPSS - Stacked Bar Charts Percentages as well. However, these charts really need to be transposed and styled, both of which you can do with chart templates.