Using external data for your graph
Using the GGraph procedure, it is possible to graph data that is not part of the IBM SPSS Statistics product. This includes comma separated values (CSV) data in a file on disk.
Graphing data in CSV files
In this example I am graphing the data from the sample file Employee Data.sav. First I opened the sample data file, and then I saved it in CSV format (File->Save As, save as type is “Comma delimited (*.csv))”. I saved it in my c:\temp directory. If you look at this file you will notice that the variable names are in the first row, and the data are in the subsequent rows.
We will be using GGraph to create this chart. Note that in order to use GGraph, you have to have a data file open, even if you aren’t going to be using the data.
Create a new syntax window (File->New->Syntax). In that syntax window create the GGraph syntax that you wish to use to create the graph, but don’t use the “/GRAPHDATASET” subcommand as we will be getting our data straight from the csv file.
For the SOURCE statement, you need to change the “userSource” to “csvSource”, and include the path name to the file where you have your data. See the example below.
GGRAPH /GRAPHSPEC SOURCE=INLINE.
SOURCE: s=csvSource(file("c:/temp/Employee data.csv"))
DATA: salary=col(source(s), name("salary"))
DATA: salbegin=col(source(s), name("salbegin"))
GUIDE: axis(dim(1), label("Current Salary"))
GUIDE: axis(dim(2), label("Beginning Salary"))
Now just run this syntax, and you will see your chart in the output window. Notice that the tick labels are not formatted (no ‘$’ prefix). This is because you are using a CSV file and the formatting information is not stored in a CSV file.
Now save your SPV file and close the output window. Edit the CSV file (I used Notepad) and make some changes. Here I deleted many cases, leaving only the first 100 cases.
your saved SPV file. Look at the
chart. You will notice that it has
changed to reflect the new data (see below).
Unlike charts created with data from within the IBM SPSS Statistics
product, this data is read every time the chart is rendered. If the data changes, the chart will change
along with it.