SPSS Chart Templates

SPSS chart templates are files that tell SPSS how to style charts in the Output Viewer window. SPSS chart templates are easy to use and make your SPSS output look very professional.

SPSS chart templates are files that tell SPSS how to style one, many or all charts that appear in the output viewer window. Examples of such styling are colors, fonts, margins and borders. The figure below shows the clustered bar chart from Association between Categorical Variables with and without a chart template applied to it.

SPSS chart template example 1SPSS chart templates can make your charts look much better.

Just like SPSS data files are sometimes called .sav files, SPSS chart templates are also known as .sgt files after their file extensions and we’ll use these two terms interchangeably. OK, let’s now get some work done and open freelancers.sav. Next, we’ll recreate the chart from the previous figure by running the syntax below.

SPSS Clustered Bar Chart Syntax

*Run clustered bar chart.

GRAPH
/BAR(GROUPED)=COUNT BY sector_2011 BY sector_2010
/TITLE=’Sector in 2010 by sector in 2011 (N = 40)’.

SPSS Chart Templates – Why?

If this were a serious project, you’d probably want the chart we just ran to look prettier. Your first intuition may be to style the chart manually, which you can do in the chart editor that opens when you double click the chart.

SPSS Chart Editor Window

It may take a bit of practice but you’ll probably figure out how to apply most of the styling you’d like to apply. However, styling charts manually will sooner or later turn out to be a bad idea: it takes way too much time and you’ll have to do everything all over if you’d like to rerun the chart for whatever reason.

This is why applying styles from an SPSS chart template is faster and safer than styling charts manually. We’ll now take a look at how it works.

Applying SPSS Chart Templates Manually

Like we just saw, double clicking a chart in SPSS will open the Chart Editor window. In this window, select File SPSS Menu Arrow Apply Chart Template. Next, navigate to the folder where the desired .sgt file is located. On our system, standard SPSS chart template files are in C:\Program Files\IBM\SPSS\Statistics\22\LooksSelect some template and click Open in order to apply it.

SPSS Chart Template Selection from Menu

Applying SPSS Chart Templates by Syntax

Although applying chart templates is preferred over styling charts manually, we strongly recommend you do so by syntax. This renders it very easy to fine tune and rerun all of your project work including setting chart templates in a matter of seconds.

By setting a chart template, it will be applied to all charts that are created after doing so. In practice, you’ll probably want to set a different chart template each time you create a different type of chart. The syntax below shows how to use SET for setting a chart template and SHOW for inspecting which chart template – if any – has been set.

Syntax for Setting a Chart Template

*1. Set chart template for all charts that follow.

set ctemplate’C:\Program Files\IBM\SPSS\Statistics\22\Looks\APA_Styles.sgt’.*2. Confirm chart template has been set.

show ctemplate.*3. Create chart with template applied to it.

GRAPH
/BAR(GROUPED)=COUNT BY sector_2011 BY sector_2010
/TITLE=’Sector in 2010 by sector in 2011 (N = 40)’.

*4. Don’t use any chart template for charts that follow.

set ctemplate none.

Saving SPSS Chart Templates

If you’d like to use SPSS chart templates, you’re by no means restricted to the .sgt files that SPSS comes with by default. Instead, you can style a chart manually and save these style definitions as your own chart template file. The screenshot below walks you through the process.

SPSS Chart Template Creation

We recommend you choose a name for your .sgt file that at least includes type of chart it addresses. An example could be “clustered_bar_title_blue.sgt”.

SPSS Chart Templates – What Are They?

Thus far, we got a basic idea of how to both save and apply SPSS chart templates. We’ll write some more on these but let’s first take a look at what .sgt files are from a technical point of view. Very similarly to SPSS table templates, SPSS chart templates are simple text files that can be opened and edited with notepad++.

SPSS chart templates contain style definitions in XML. This XML code can be edited manually but this is rather challenging. However, it’s a fast and efficient way for developing chart templates and it can get a lot of things done that you can’t get done otherwise.

SPSS Chart Template Development

If you wish to create your own chart templates, we recommend you create a separate one for each different type of chart you’d like to use in one of your reports. Note that chart templates can be developed iteratively: you may apply a template to a chart, apply some manual styling to the chart and then save the chart’s current styles as an improved version of the template you just applied to it.

SPSS Chart Templates – Keeping Things Organized

When using chart templates in real life projects, we strongly recommend you copy all chart templates you use for some project to this folder as well; in case you’d ever want to replicate (part of) your work, you can be confident you’ll still have them available. In contrast to table templates, a CD command allows you to use relative paths for setting chart templates. Doing so renders your syntax a bit cleaner and more flexible. The syntax below gives an example.

*1. Set project folder as default folder.

cd ‘d:/project’.*2. Set chart template to ‘d:/project/my_chart_template.sgt’ now requires just the file name (= relative path).

set ctemplate’my_chart_template.sgt’.

SPSS Chart Templates – Showcase

Readers who have the SPSS Python Essentials installed and running can loop over all chart templates that are included in SPSS. The syntax below does just that. Note that rdir (boldfaced in the syntax below) should be set to the previously mentioned Looks folder holding the .sgt files.

Python Loop over Chart Templates Syntax

*Create separate chart for each SPSS chart template file in Looks folder.

begin program.
rdir = r’C:\Program Files\IBM\SPSS\Statistics\22\Looks‘ #Set to SPSS Looks folder
import spss,os
for sgt in [fil for fil in os.listdir(rdir) if fil.endswith(‘.sgt’)]:
spss.Submit(”’
title %s.
set ctemplate ‘%s’.
GRAPH /BAR(GROUPED)=COUNT BY sector_2011 BY sector_2010
/TITLE=’Sector in 2010 by sector in 2011 (N = 40)’.
”’%(sgt,os.path.join(rdir,sgt)))
end program.