UCLA Academic Technology Services HomeServicesClassesContactJobs

SPSS FAQ
How can I graph two (or more) groups using different symbols?

Suppose we are using the High School and Beyond data file (hsb2) which has test scores for 200 students, which contains data on 91 male and 109 female students.  We could make a graph of their read and write scores as shown below with the graph command.

get file 'c:\hsb2.sav'.

graph
 /scatterplot(bivar) = write with read.
 Scatter of read write 

Now, let's make a graph where we see the scores separately for the males and the females.  We will use the by option with the graph command, and SPSS will assign different symbols to each group.

graph
  /scatterplot=read with write by female.


Scatter of write read by female

If you would like to change the symbols (SPSS calls them "markers") used for the groups, double click on the graph to open the chart editor, select select "format", then "marker", and then select the marker and the size that you would like.  Click on "apply", "close" and then close the chart editor.  If you would like to have different markers for the different groups, double click on the graph, double click on the legend on the right that labels the groups, and select (i.e., single click on) the group whose marker you would like to change.  Next, select "format", "marker", and then select the marker and the size that you would like.  Click on "apply", click on "close" and then close the chart editor.

graph
  /scatterplot=read with write by female.

Scatter of write read by female

The igraph command can also be used to make this type of scatterplot.  For example,

igraph
  /x1=var(read) 
  /y=var(write) 
  /color=var(female) type=categorical 
  /catorder var(female) (ascending values omitempty)
  /scatter coincident=none.

If you are using SPSS version 14 or higher, you can also use the ggraph command to create a scatterplot.  For example,

* Chart Builder.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=read write female MISSING=
  LISTWISE REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
 SOURCE: s=userSource(id("graphdataset"))
 DATA: read=col(source(s), name("read"))
 DATA: write=col(source(s), name("write"))
 DATA: female=col(source(s), name("female"), unit.category())
 GUIDE: axis(dim(1), label("reading score"))
 GUIDE: legend(aesthetic(aesthetic.color.exterior), label("female"))
 SCALE: cat(aesthetic(aesthetic.color.exterior), include(".00", "1.00"))
 ELEMENT: point(position(read*write), color.exterior(female))
END GPL.

The main difference between these commands is the graph editor associated with it.  In other words, each graph command has its own graph editor, and each graph editor has slightly different options, etc.  If you do not find the option that you want when making the graph with one command, you can use a different graph command (e.g., graph, igraph or ggraph), and that command might have the option that you seek.


How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.