LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (August 2008)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 25 Aug 2008 13:31:02 -0600
Reply-To:     ViAnn Beadle <vab88011@gmail.com>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         ViAnn Beadle <vab88011@gmail.com>
Subject:      Re: Bar Graph
Comments: To: Rhonda Boorman <rboorman@tpg.com.au>
In-Reply-To:  <002c01c90634$aa272d10$fe758730$@com.au>
Content-Type: text/plain; charset="us-ascii"

Two graphics procedures within SPSS produce "paneled" charts--GGRAPH and IGRAPH. Both provide UIs to generate panels provided that the thing defining the panels is a categorical variable. You, however, don't have a categorical variable with your current structure. So the first thing to do is to restructure the data using VARSTOCASES so that you halve the number of variables but double your cases.

STEP 1: Restructure the data Assume you have 2 variables xbefore and xafter and for the 1st case you have values 1 and 3. When you restructure the file you now have 2 variables but the variables are x and index and there are two cases that look like this:

1 1 3 2

So given your 50 variables, you'll have 26 variables, 1 for each pair and 1 for the index. Here's some syntax that first generates 10 variables and then creates the pairs using VARSTOCASES:

input program. loop #i = 1 to 100. do repeat x = x1 to x10/ y=y1 to y10. compute x=trunc(uniform(4))+1. compute y=trunc(uniform(4)) +1. end repeat. end case. end loop. end file. end input program. execute.

VARSTOCASES /ID=id /MAKE v1 FROM x1 y1 /MAKE v2 FROM x2 y2 /MAKE v3 FROM x3 y3 /MAKE v4 FROM x4 y4 /MAKE v5 FROM x5 y5 /MAKE v6 FROM x6 y6 /MAKE v7 FROM x7 y7 /MAKE v8 FROM x8 y8 /MAKE v9 FROM x9 y9 /MAKE v10 FROM x10 y10 /INDEX=Index(2) /KEEP= /NULL=KEEP. VALUE LABELS Index 1 "Before" 2 "After".

STEP 2 Generate the Chart There are three procedures in SPSS that produce histograms: GRAPH, GGRAPH, and IGRAPH. We can eliminate GRAPH because it doesn't support paneling. So we're left with GGRAPH and IGRAPH.

A histogram assumes that have continuous data and attempts to bin the values into buckets. But you have variables that take on only 4 values so there is no need to bin the values into buckets. So, you can use a simple bar chart to show the distribution. There are a few complications, however. If you define the variable as SCALE you'll get tick values like 0.0, 0.5, ... when you want want tick values 1, 2, 3, 4.

You can get nice tick values for your charts by defining your variable as categorical. But this also presents some problems. You know your question takes on values 1 to 4 but a IGRAPH doesn't know that. If you define your variable as categorical and an individual value such as 4 has a count of 0, the x-axis will only show 3 values. If you use IGRAPH, you have to define the variable as SCALE and will get messy tick labels. IGRAPH presents another problem, it panels the two charts vertically.

That leaves the GGRAPH command. You can tell the GGRAPH command that your variable takes on 4 values so every panel for every question with have the same number of tick marks but might not show all bars as present. GGRAPH provides horizontal or vertical paneling. So your best solution is the GGRAPH command.

Here's the syntax for IGRAPH for my sample data:

IGRAPH /VIEWNAME='Bar Chart' /X1=VAR(v1) TYPE=SCALE /Y=$count /PANEL=VAR(Index) /COORDINATE=VERTICAL /YLENGTH=5.2 /X1LENGTH=6.5 /CHARTLOOK='NONE' /CATORDER VAR(Index) (ASCENDING VALUES OMITEMPTY) /BAR KEY=ON SHAPE=RECTANGLE BASELINE=AUTO.

Note the /PANEL command which uses the Index variable to panel the two charts.

Here's the syntax for GGRAPH for my sample data:

GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=v1 COUNT()[name="COUNT"] Index MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: v1=col(source(s), name("v1"), unit.category()) DATA: COUNT=col(source(s), name("COUNT")) DATA: Index=col(source(s), name("Index"), unit.category()) GUIDE: axis(dim(1), label("Variable 1")) GUIDE: axis(dim(2), label("Count")) GUIDE: axis(dim(3), label("Index"), opposite()) SCALE: cat(dim(1), include("1","2","3","4")) SCALE: cat(dim(3), include("1", "2")) ELEMENT: interval(position(v1*COUNT*Index), shape.interior(shape.square)) END GPL.

Note the SCALE statement in which the include function forces four categories. Note also that the syntax explicitly specifies an axis label for the variable. If you want a nice label, you'll have to provide it on the GUIDE statement for axis(dim(1).

Each command charts of your original pairs of variables. But you have 25 pairs. You can create a macro to generate all the charts or just copy, paste, and edit each command substituting the variable name and variable label as required. You might also use the UI (Chart Builder for GGRAPH) to create your syntax. If you do that, label your new variables and specify values labels for values 1, 2, 3, and 4 to have it generate the include function and label for the X axis.

This should give you something to chew on for a while.

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Rhonda Boorman Sent: Sunday, August 24, 2008 3:59 PM To: SPSSX-L@LISTSERV.UGA.EDU Subject: FW: Bar Graph

Hi ViAnn My data is organised as one variable for pre and one variable for post, for the same item on the survey. The survey contained 25 items, and it was completed once prior to the intervention and once following the intervention. Rhonda

[Vi sez:] <snip/>

===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD


Back to: Top of message | Previous page | Main SPSSX-L page