Stumped by simple line graph problem

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Stumped by simple line graph problem

Nils-Eivind Naas
Dear list members,

I am stumped by a seemingly simple line graph problem.
I have to add that I have not done anything serious with SPSS graphics
during my 35 years as SPSS user and coordinator/support person,
improbable as it sounds :-)

My problem is simple;
first, I want to create a line plot of the raw values of 12 selected
cases on 16 (or 32) variables.
Each of the 16 variables should represent a point on the X axis, the Y
axis should represent the actual variable value (between 0 and 100).

Second, I want to plot the means of the same variables for 2 groups of
cases, defined by a binary variable. Ideally, the 2 lines should appear
in the same diagram as the first graph, but I'll settle for a separate
graph :-)

I hope someone can point me in the right direction.
I have SPSS 15 for Windows and 16 for Mac available, if that makes a
difference.

--
Nils-Eivind Naas
Oslo

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (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
Reply | Threaded
Open this post in threaded view
|

Re: Stumped by simple line graph problem

ViAnn Beadle
Let's see if I've got this straight.

For plot 1, you want 12 lines each corresponding to a selected case. The x
axis contains the names of the 16 or 32 variables.

For plot 2, you want 2 lines, each corresponding to the mean of your 16
variables for two groups. The x axis contains the name of the 16 or 32
variables.

I'd call neither of these simple line graphs which typically have categories
of a single variable on the x axis. SPSS can do the charts I've described.
Are these what you want?

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Nils-Eivind Naas
Sent: Tuesday, February 26, 2008 9:09 AM
To: [hidden email]
Subject: Stumped by simple line graph problem

Dear list members,

I am stumped by a seemingly simple line graph problem.
I have to add that I have not done anything serious with SPSS graphics
during my 35 years as SPSS user and coordinator/support person,
improbable as it sounds :-)

My problem is simple;
first, I want to create a line plot of the raw values of 12 selected
cases on 16 (or 32) variables.
Each of the 16 variables should represent a point on the X axis, the Y
axis should represent the actual variable value (between 0 and 100).

Second, I want to plot the means of the same variables for 2 groups of
cases, defined by a binary variable. Ideally, the 2 lines should appear
in the same diagram as the first graph, but I'll settle for a separate
graph :-)

I hope someone can point me in the right direction.
I have SPSS 15 for Windows and 16 for Mac available, if that makes a
difference.

--
Nils-Eivind Naas
Oslo

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (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

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (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
Reply | Threaded
Open this post in threaded view
|

Re: Stumped by simple line graph problem

Nils-Eivind Naas
ViAnn Beadle skrev:

> Let's see if I've got this straight.
>
> For plot 1, you want 12 lines each corresponding to a selected case. The x
> axis contains the names of the 16 or 32 variables.
>
> For plot 2, you want 2 lines, each corresponding to the mean of your 16
> variables for two groups. The x axis contains the name of the 16 or 32
> variables.
>
> I'd call neither of these simple line graphs which typically have categories
> of a single variable on the x axis. SPSS can do the charts I've described.
> Are these what you want?

You hit the nail precisely. These are exactly what I am after.

--
Nils-Eivind Naas

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (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
Reply | Threaded
Open this post in threaded view
|

Re: Stumped by simple line graph problem

ViAnn Beadle
The trick here to make this easy is to flip the file. The following syntax
first creates some data to match your description. What you need to
concentrate on is the VARSTOCASES command and then the GGRAPH commands. Note
that the syntax for the GGRAPH commands was created from the Chart Builder.

* use an input program to create some data.
input program.
loop #i=1 to 12.
do repeat y=y1 to y16.
compute y=abs(normal(5)).
end repeat.
* create the dichotomous variable.
compute dichot=rnd(uniform(1)).
end case.
end loop.
end file.
end input program.
******************* end of data generation ******************.
* compute a caseid variable.
compute caseid=$casenum.

* now flip the file using VARSTOCASES to make charting easier.

VARSTOCASES
  /MAKE yvars FROM y1 y2 y3 y4 y5 y6 y7 y8 y9 y10 y11 y12 y13 y14 y15 y16
  /INDEX=yvarindex(yvars)
  /KEEP=caseid dichot
  /NULL=KEEP.


* Chart Builder.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=yvarindex yvars
caseid[LEVEL=NOMINAL]
    MISSING=LISTWISE REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: yvarindex=col(source(s), name("yvarindex"), unit.category())
  DATA: yvars=col(source(s), name("yvars"))
  DATA: caseid=col(source(s), name("caseid"), unit.category())
  GUIDE: legend(aesthetic(aesthetic.color.interior), label("caseid"))
  SCALE: linear(dim(2), include(0))
  SCALE: cat(dim(1), sort.values("y1", "y2", "y3", "y4", "y5", "y6", "y7",
"y8", "y9", "y10",
    "y11", "y12", "y13", "y14", "y15", "y16"))
  ELEMENT: line(position(yvarindex*yvars), color.interior(caseid),
missing.wings())
END GPL.

* Chart Builder.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=yvarindex
MEAN(yvars)[name="MEAN_yvars"]
    dichot[LEVEL=NOMINAL] MISSING=LISTWISE REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: yvarindex=col(source(s), name("yvarindex"), unit.category())
  DATA: MEAN_yvars=col(source(s), name("MEAN_yvars"))
  DATA: dichot=col(source(s), name("dichot"), unit.category())
  GUIDE: axis(dim(1), label("yvarindex"))
  GUIDE: axis(dim(2), label("Mean yvars"))
  GUIDE: legend(aesthetic(aesthetic.color.interior), label("dichot"))
  SCALE: linear(dim(2), include(0))
  SCALE: cat(dim(1), sort.values("y1", "y2", "y3", "y4", "y5", "y6", "y7",
"y8", "y9", "y10",
    "y11", "y12", "y13", "y14", "y15", "y16"))
  ELEMENT: line(position(yvarindex*MEAN_yvars), color.interior(dichot),
missing.wings())
END GPL.

-----Original Message-----
From: Nils-Eivind Naas [mailto:[hidden email]]
Sent: Wednesday, February 27, 2008 12:43 AM
To: ViAnn Beadle; [hidden email]
Subject: Re: Stumped by simple line graph problem

ViAnn Beadle skrev:

> Let's see if I've got this straight.
>
> For plot 1, you want 12 lines each corresponding to a selected case. The x
> axis contains the names of the 16 or 32 variables.
>
> For plot 2, you want 2 lines, each corresponding to the mean of your 16
> variables for two groups. The x axis contains the name of the 16 or 32
> variables.
>
> I'd call neither of these simple line graphs which typically have
categories
> of a single variable on the x axis. SPSS can do the charts I've described.
> Are these what you want?

You hit the nail precisely. These are exactly what I am after.

--
Nils-Eivind Naas

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (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
Reply | Threaded
Open this post in threaded view
|

Re: Stumped by simple line graph problem

Nils-Eivind Naas
ViAnn Beadle skrev:
> The trick here to make this easy is to flip the file. The following syntax
> first creates some data to match your description. What you need to
> concentrate on is the VARSTOCASES command and then the GGRAPH commands. Note
> that the syntax for the GGRAPH commands was created from the Chart Builder.

< Long GPL program deleted >

Thank you very much.
This indeed did the trick.

There are one or 2 problems, however.

First, in the second graph the variables come in the "wrong" order. In
the first graph, the x-axis presents the 16 variables in the order
specified on the VARSTOCASES MAKE command, as expected. But in the
second, the order is the sort order of the variable names (the first
variable name starts with k45 and the last with k03), and on the second
graph the k03... variable comes first. Since the data is in fact some
form of time series from 1945 to 2003, this is not exactly what I want.
It is easy to rename the variables, but I am curious about the reason
for the different behaviour of the 2 commands.

Second, the graphs come in splendid colours. They are supposed to be
printed in a student's master thesis, however, and I am not sure if she
is able to use colours in printing. If that cannot be done, how do I ask
for line symbols in black-and-white?

Third, I do of course need a descriptive header above each graph.
Presumably, another label definition on some GUIDE command?

I realize I have some catching-up to do. Or set a younger colleague in
motion :-) Ironically, I bought Leland Wilkinson's book when it was
fresh from the press, but I never had the time nor the inclination to
grapple with it. Perhaps the time is now :-)

Thank you again. I (and my student) am deeply grateful for your help.

--
Nils-Eivind Naas
Institute for Social Research
Oslo

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (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