|
Hello,
I need help with finding an appropriate graph in SPSS (or the right way to do it). I am trying to generate a graph on which I can show the distribution of 2 scale variables. I have tried all versions of histograms and nothing seems to work. I have tried to use Excel but the large sample size (n=841) makes the graph unreadable. Thank you, Hilda. |
|
Here's an example using GPL with the employee data.sav example file. It creates two histograms side by side.
GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=salary salbegin MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: salary=col(source(s), name("salary")) DATA: salbegin=col(source(s), name("salbegin")) GUIDE: axis(dim(1), label("Salary")) GUIDE: axis(dim(2), label("Frequency")) ELEMENT: interval(position(summary.count(bin.rect(salbegin/"Beginning Salary"+salary/"Current Salary"))), shape.interior(shape.square)) END GPL. Another approach is to use the VARSTOCASE command to take your two variables and create cases from each variable with an index variable. The you can create a stacked histogram: VARSTOCASES /ID=id1 /MAKE trans1 FROM salbegin salary /INDEX=Index1(trans1) /KEEP= /NULL=KEEP. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=trans1 Index1 MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: trans1=col(source(s), name("trans1")) DATA: Index1=col(source(s), name("Index1"), unit.category()) GUIDE: axis(dim(1), label("Beginning Salary")) GUIDE: axis(dim(2), label("Frequency")) GUIDE: legend(aesthetic(aesthetic.color.interior), label("Index1")) ELEMENT: interval.stack(position(summary.count(bin.rect(trans1))), color.interior(Index1), shape.interior(shape.square)) END GPL. From: [hidden email] [mailto:[hidden email]] Sent: Sunday, May 27, 2007 6:57 AM To: Beadle, ViAnn Subject: RE: Graphs I am using version 15. -------------- Original message -------------- From: "Beadle, ViAnn" <[hidden email]> > what release of SPSS are you using > > -----Original Message----- > From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Nyougo > Omae. > Sent: Saturday, May 26, 2007 7:33 PM > To: [hidden email] > Subject: Graphs > > Hello, > > I need help with finding an appropriate graph in SPSS (or the right way to do > it). > > I am trying to generate a graph on which I can show the distribution of 2 scale > variables. I have tried all versions of histograms and nothing seems to work. I > have tried to use Excel but the large sample size (n=841) makes the graph > unreadable. > > Thank you, > > Hilda. |
|
If you want to compare the distributions of the two variables, another way to do the plot would be to overlay two histograms on top of each other, being careful that they have the same bar parameters. Here is an example of one way to do this. It has a little bit of transparency on the bars in front so that the histogram behind shows through. (I am using SPSS 15. In SPSS 14 the transparency parameter was interpreted differently.)
GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=ALL MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE . BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: salary = col(source(s), name("salary")) DATA: salbegin = col(source(s), name("salbegin")) GUIDE: axis(dim(1), label("Salary and Starting Salary")) GUIDE: axis(dim(2), label("Count")) SCALE: linear(dim(2), include(0)) ELEMENT: interval(position(summary.count(bin.rect(salary,binStart(5000),binWidth(5000)))), color(color.blue) ,transparency(transparency."0.0"))) ELEMENT: nterval(position(summary.count(bin.rect(salbegin,binStart(5000), binWidth(5000)))),color(color.lightblue) ,transparency(transparency."0.2"))) END GPL. Regards, Jon Peck -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Beadle, ViAnn Sent: Sunday, May 27, 2007 8:33 AM To: [hidden email] Subject: Re: [SPSSX-L] Graphs Here's an example using GPL with the employee data.sav example file. It creates two histograms side by side. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=salary salbegin MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: salary=col(source(s), name("salary")) DATA: salbegin=col(source(s), name("salbegin")) GUIDE: axis(dim(1), label("Salary")) GUIDE: axis(dim(2), label("Frequency")) ELEMENT: interval(position(summary.count(bin.rect(salbegin/"Beginning Salary"+salary/"Current Salary"))), shape.interior(shape.square)) END GPL. Another approach is to use the VARSTOCASE command to take your two variables and create cases from each variable with an index variable. The you can create a stacked histogram: VARSTOCASES /ID=id1 /MAKE trans1 FROM salbegin salary /INDEX=Index1(trans1) /KEEP= /NULL=KEEP. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=trans1 Index1 MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: trans1=col(source(s), name("trans1")) DATA: Index1=col(source(s), name("Index1"), unit.category()) GUIDE: axis(dim(1), label("Beginning Salary")) GUIDE: axis(dim(2), label("Frequency")) GUIDE: legend(aesthetic(aesthetic.color.interior), label("Index1")) ELEMENT: interval.stack(position(summary.count(bin.rect(trans1))), color.interior(Index1), shape.interior(shape.square)) END GPL. From: [hidden email] [mailto:[hidden email]] Sent: Sunday, May 27, 2007 6:57 AM To: Beadle, ViAnn Subject: RE: Graphs I am using version 15. -------------- Original message -------------- From: "Beadle, ViAnn" <[hidden email]> > what release of SPSS are you using > > -----Original Message----- > From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Nyougo > Omae. > Sent: Saturday, May 26, 2007 7:33 PM > To: [hidden email] > Subject: Graphs > > Hello, > > I need help with finding an appropriate graph in SPSS (or the right way to do > it). > > I am trying to generate a graph on which I can show the distribution of 2 scale > variables. I have tried all versions of histograms and nothing seems to work. I > have tried to use Excel but the large sample size (n=841) makes the graph > unreadable. > > Thank you, > > Hilda. |
| Free forum by Nabble | Edit this page |
