SPSS Statistics

SPSS Statistics

Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers! 

 View Only

Hacking the default SPSS chart template

By Archive User posted Tue January 03, 2012 08:58 PM

  
In SPSS charts, not every element of the chart is accessible through syntax. For example, the default chart background in all of the versions I have ever used is light grey, and this can not be specified in GPL graphing statements. Many of such elements are specified in chart template files (.sgt extension). Chart template files are just a specific text format organized using an xml tag structure. Below is an example scatterplot with the default chart template for version 19.



You can manually edit graphics and save chart templates, but here I am going to show some example changes I have made in the default chart template. I do this because when you save chart templates by manually editing charts, SPSS has defaults for many different types of charts (one example when it changes are if the axes are categorical or numeric). So it is easier to make widespread changes by editing the main chart template.

The subsequent examples were constructed from a chart template originally from version 17, and I will demonstrate 3 changes I have made to my own chart template.

1) Change the background color from grey to transparent.
2) Make light grey, dashed gridlines the default.
3) Change the font.

Here I just copied and saved my own version of the template renamed in the same folder. You can then open up the files in any text editor. I use Notepad++, and it has a nice default plug-in that allows me to compare the original template file with my updated file. Moving on to how to actually make changes.

1) Change the background color.

The original chart color (in RGB hexidecimal code) is "F0F0F0" (you can open up a default chart to see the decimal representation, 240-240-240). Then I just used this online tool to convert the decimal to hexidecimal, and then you can search the template for this color. The background color is only located in one place in the template file, in a <style> tag nested within an <addFrame> tag. I changed "F0F0F0" to "transparent" as oppossed to another RGB color. One might want to use white for the background as well ("FFFFFF").

2) Make light grey, dashed gridlines the default

Sometimes I can't figure out how to exactly edit the original template to give me what I want. One way to get the "right" code is to manually apply the edits within the output, and save the chart template file to demonstrate how specific tag elements are structured. To get the gridlines I did this, and figured out that I needed to insert a set of <gridLines> tag with my wanted aesthetic specifications within the <majorTicks> tag (that is within a <setAxisMajorTicks> tag). So, in my original chart template file the code was;


<setAxisMajorTicks>
<majorTicks categorical="false" role="x" styleOnly="true">
<markStyle>
<style color="black" stroke-width="1pt"/>
</markStyle>
<tickLabelStyle>
<style number="0" color="black" font-size="8pt;6pt"/>
<style number="1" visible="false"/>
</tickLabelStyle>
</majorTicks>
</setAxisMajorTicks>


and below is what I inserted;

<setAxisMajorTicks>
<majorTicks categorical="false" role="x" styleOnly="true">
<gridLines>
<style color="#cccccc" stroke-dasharray="3px,6px" stroke-width="0.5pt" visible="true"/>
</gridLines>
<markStyle>
<style color="black" stroke-width="1pt"/>
</markStyle>
<tickLabelStyle>
<style number="0" color="black" font-size="8pt;6pt"/>
<style number="1" visible="false"/>
</tickLabelStyle>
</majorTicks>
</setAxisMajorTicks>


I then inserted the gridlines tag within all of the <setAxisMajorTicks> tags (you have several for different axis's and whether the axis's are cateogorical or numeric).

3) Change the font

This one was really easy to change. The default font is Sans-Serif. I just searched the file for Serif, and it is only located within one place, within a <style> tag nested within an <addFrame> tag (near, but not within, the same place as the bacground color). Just change the "SansSerif" text to whatever you prefer, for example "Calibri". I don't know what fonts are valid (if it is dependent on your system or on what is available in SPSS).

Here is what the same scatterplot at the beginning of the post looks like with my updated chart template.



Besides this my only other advice is combing through the original chart template and using trial and error to change items. For example, for many bar charts the default RGB color is tan (D3CE97). You can change that to whatever you want by just doing a find and replace of that hexidecimal code with another valid hexidecimal color code (like BEBEBE for light grey).

These changes are all arbitrary and are just based on personal preference, but should be enlightening as to how to make such modifications. Other ones I suspect people may be interested in are the default color or other aesthetic schemes (such as point shapes). These are located at the end of my original chart template file within the <cycle> tags. One for instance could change the default colors to be more printer friendly. It would be easier to save a set of different templates for color schemes (either categorical or continuous) than doing the map statements within GPL all the time (although you would need to have your categories ordered appropriately). Other things you can change are the font sizes, text alignment, plot margins, default pixel size for charts, and probably a bunch of other stuff I don't know about.

I've saved my current chart template file at this Google code site for anyone to peruse. I've made a few more changes than I've listed here, but not many. Let me know in the comments if you have any examples of changing elements in your chart template file!

Below is some quick code that sets the chart templates to the file I made and produces the above scatterplots.


***********************************.
*original template location.
FILE HANDLE orig_temp /name = "C:Program FilesIBMSPSSStatistics19template".
*updated template location.
FILE HANDLE update_temp /name = "E:BLOGSPSSGRAPHSHacking_Chart_Template".
*making fake, data, 100 cases.
input program.
loop #i = 1 to 100.
compute V1 = RV.NORM(0,1).
compute V2 = RV.NORM(0,1).
end case.
end loop.
end file.
end input program.
execute.
*original template.
SET CTemplate='orig_tempchart_style.sgt'.
*Scatterplot.
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=V1 V2 MISSING=LISTWISE REPORTMISSING=NO
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
SOURCE: s=userSource(id("graphdataset"))
DATA: V1=col(source(s), name("V1"))
DATA: V2=col(source(s), name("V2"))
GUIDE: axis(dim(1), label("V1"))
GUIDE: axis(dim(2), label("V2"))
ELEMENT: point(position(V1*V2))
END GPL.
*My updated template.
SET CTemplate='update_tempchart_style(AndyUpdate).sgt'.
*Scatterplot.
GGRAPH
/GRAPHDATASET NAME="graphdataset" VARIABLES=V1 V2 MISSING=LISTWISE REPORTMISSING=NO
/GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
SOURCE: s=userSource(id("graphdataset"))
DATA: V1=col(source(s), name("V1"))
DATA: V2=col(source(s), name("V2"))
GUIDE: axis(dim(1), label("V1"))
GUIDE: axis(dim(2), label("V2"))
ELEMENT: point(position(V1*V2))
END GPL.
***********************************.






#datavisualization
#SPSS
#SPSSStatistics
#Visualization
15 comments
6 views

Permalink

Comments

Fri May 01, 2020 07:53 PM

Hi

remember searching for hacked SPSS need to be checked first. some hackers try using these hacking tools to access your systems. you need to know about exploit too like Silent Exolit

Fri July 14, 2017 03:42 PM

Dear Andrew, I am so happy finding such a convenient way changing the font settings. Are you aware of how I need to safe the file after changes to make sure after changing SPSS still accepts it as a template? It doesnt accept the changes in a text editor, I wanted diagrams in Times New Roman.
Best Heike

Sun February 28, 2016 02:06 PM

For SPSS (Statistics) the answer is no. I do not know the answer for Modeler specifically. You might try the forums to ask that question.

Sat February 27, 2016 10:10 PM

Hi,

Is there a way to use a jpg, bmp or tiff as a chart background in modeler?

Thanks

Fri March 06, 2015 02:30 PM

This message was posted by a user wishing to remain anonymous
[…] Which produces this chart (ok I cheated alittle, I post-hoc added the labels in by hand in the SPSS editor, as I did not like the automatic label placement and it is easier to add in by hand than fix the automated labels). Also note this will appear slightly different than the default SPSS charts because I use my own personal chart template. […]

Tue February 10, 2015 02:50 PM

That is great! Thanks a lot, Andrew, this was very helpful!

Tue February 10, 2015 01:35 PM

Here is a link to the current one I am using Marcus, https://www.dropbox.com/s/drnd9nddedd8w6m/chart_style%28AndyW2-presentation%29.sgt?dl=0

In mine I have the font for the tick marks set to 12 point font (I agree the default is too small, especially for presentations). In mine in that same "style" tag that contains the font option I have the option [ font-size="12pt" ]. I'm pretty sure this controls it globally for all the axis tick marks.

Tue February 10, 2015 01:22 PM

Dear Andrew!

This is of enormous help! Thanks!

I would be interested to fix the x tick and y tick labels at Arial 16 pt, in order to have it nicely visible. The Arial is easy when following your description. But could you point me to the place where the 16pt need to be? I have exchanged all 11pt in your file, but no change was visible...

Thanks in advance!
Markus

Wed January 14, 2015 08:53 AM

This message was posted by a user wishing to remain anonymous
[…] to get the labels like this my chart template specifies the style of data labels […]

Thu January 02, 2014 09:58 AM

This message was posted by a user wishing to remain anonymous
[…] posts of Comparing continuous distributions of unequal size groups in SPSS (2,468 total views), Hacking the default SPSS chart template (2,237), and Avoid Dynamite Plots! Visualizing dot plots with super-imposed confidence intervals in […]

Fri January 11, 2013 02:28 PM

This message was posted by a user wishing to remain anonymous
[...] I frequently get web-traffic via general google searches of SPSS + something else I blogged about (hacking the template and comparing continuous distributions are my two top [...]

Sun June 17, 2012 10:18 AM

This message was posted by a user wishing to remain anonymous
[...] on the X axis versus the Robbery Rate per 100,000 on the Y axis. This uses my personal default chart template, but the problem is with the large over-plotted points in the scatter, which is the same for the [...]

Sun May 20, 2012 07:43 AM

This message was posted by a user wishing to remain anonymous
[...] transparent), but most of those things can likley be more steamlined by making an appropriate chart template. Two things I do not like, which I may need to edit the chart template to be able to accomplish [...]

Fri January 06, 2012 06:25 PM

Hi Jon, thanks for the reminder. I certainly did forget that was an option!

Thu January 05, 2012 08:29 PM

Don't forget that some of these changes such as the default font, marker, and graphic element color can be made systemwide via Edit>Options>Charts. You can also designate alternate templates in that panel. But having the default and other templates in xml makes it easy or at least easier to make the kinds of changes you discuss.

Regards,
Jon Peck