Horizontal Stacked Bar Chart with Mirroring

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

Horizontal Stacked Bar Chart with Mirroring

Peter Cuttance
I am looking for GPL or other SPSS code to build charts of the sort displayed at the URL below (this
List serve does not allow pasting of graphics).

  https://www.radii.org/doc   click on  LIKERT STACKED BAR CHART.jpg

The Charts show responses for a set of Likert Scales, with the negative responses stacked to the left
of the origin and the positive responses stacked to the right.

The scale to both the left and right of the origin ranges from 0–100 (with the origin as zero).

Has anyone developed code for a chart such as this — or have suggestions of the best strategy to
approach the task.

=====================
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: Horizontal Stacked Bar Chart with Mirroring

Albert-Jan Roskam
Hi,
 
I'd use the R library ggplot2 for this (http://had.co.nz/ggplot2/geom_bar.html)
You could simply use negative values for the left side of the plot, but label the axis
with whatever values you like.

Cheers!!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--- On Mon, 7/5/10, Peter Cuttance <[hidden email]> wrote:

From: Peter Cuttance <[hidden email]>
Subject: [SPSSX-L] Horizontal Stacked Bar Chart with Mirroring
To: [hidden email]
Date: Monday, July 5, 2010, 4:51 AM

I am looking for GPL or other SPSS code to build charts of the sort displayed at the URL below (this
List serve does not allow pasting of graphics).

  https://www.radii.org/doc   click on  LIKERT STACKED BAR CHART.jpg

The Charts show responses for a set of Likert Scales, with the negative responses stacked to the left
of the origin and the positive responses stacked to the right.

The scale to both the left and right of the origin ranges from 0–100 (with the origin as zero).

Has anyone developed code for a chart such as this — or have suggestions of the best strategy to
approach the task.

=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@... (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: Horizontal Stacked Bar Chart with Mirroring

ViAnn Beadle

The example is not well labeled as to what distinguishes the bars. I’m going to assume that each bar is associated with a separate variable.

 

A paneled “population pyramid” will provide the mirrored bars using GPL. A population pyramid has a splitting dimension to produce the left-right panels, a categorical dimension mapped to the vertical axis and a summary variable mapped to the horizontal axis for each split.

 

A big hurdle in generating charts within SPSS is to get the data organized in the way that the code expects it. To define one categorical variable corresponding to each bar, I’m going to use VARSTOCASES to generate an index variable corresponding to the separate variables and summary variable corresponding to the response.

 

I’m also getting to assume that response variable had categories like Strongly Agree, Agree, No Opinion, Disagree, and Strongly Disagree. Since the splitter is binary the values are recoded into 2 categories, Agree and Disagree. Here’s the full example with some totally fabricated data.

****************************************************

* Define three variables.

data list list / var1 var2 var3.

value labels var1 var2 var3 1 'Strongly Agree' 2 'Agree' 3 'No Opinion' 4 'Disagree' 5 'Strongly Disagree'.

begin data

1 1 1

2 1 3

3 3 2

1 2 3

2 2 1

3 2 1

4 3 4

5 2 4

5 4 4

3 5 5

2 1 4

3 2 5

1 4 5

4 5 1

3 3 3

end data.

 

* Transpose  the data to get the index and response value.

VARSTOCASES

  /ID=id

  /MAKE Response FROM var1 var2 var3

  /INDEX=Question(3)

  /KEEP=

  /NULL=KEEP.

 

* Label the index variable.

value labels Question 1 'Question 1' 2 'Question 2' 3 'Question 3'.

 

 

* Initialize and create the splitter variable with RECODE.

numeric opinion.

Recode Response (1 2 = 1) (4 5 = 2) into Opinion.

variable level opinion (nominal).

value labels opinion 1 'Agree' 2 'Disagree'.

 

* Use GGRAPH to create the chart.

GGRAPH

  /GRAPHDATASET NAME="graphdataset" VARIABLES=COUNT()[name="COUNT"] Question opinion

    MISSING=LISTWISE REPORTMISSING=NO

  /GRAPHSPEC SOURCE=INLINE.

BEGIN GPL

  SOURCE: s=userSource(id("graphdataset"))

  DATA: COUNT=col(source(s), name("COUNT"))

  DATA: Question=col(source(s), name("Question"), unit.category())

  DATA: opinion=col(source(s), name("opinion"), unit.category())

  COORD: transpose(mirror(rect(dim(1,2))))

  GUIDE: axis(dim(1))

  GUIDE: axis(dim(1), opposite())

  GUIDE: axis(dim(2), label("Count"))

  GUIDE: axis(dim(3), opposite(), gap(0px))

  GUIDE: legend(aesthetic(aesthetic.color), null())

  SCALE: cat(dim(1), include("1", "2", "3"))

  SCALE: linear(dim(2), min(0))

  SCALE: cat(dim(3), include("1.00", "2.00"))

  ELEMENT: interval(position(Question*COUNT*opinion), color.interior(opinion))

END GPL.

************************************************************

 

Notes:

1.       There are 3 data dimensions: Count which is mapped to Y; Question which is mapped to X; and opinion which is mapped to the panels.

2.       The COORD statement flips X and Y mirrors the panels with the mirror function.

3.       The SCALE statement for the Y dimension sets the minimum value to 0.

 

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Albert-Jan Roskam
Sent: Monday, July 05, 2010 1:48 AM
To: [hidden email]
Subject: Re: Horizontal Stacked Bar Chart with Mirroring

 

Hi,

 

I'd use the R library ggplot2 for this (http://had.co.nz/ggplot2/geom_bar.html)

You could simply use negative values for the left side of the plot, but label the axis

with whatever values you like.

Cheers!!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--- On Mon, 7/5/10, Peter Cuttance <[hidden email]> wrote:


From: Peter Cuttance <[hidden email]>
Subject: [SPSSX-L] Horizontal Stacked Bar Chart with Mirroring
To: [hidden email]
Date: Monday, July 5, 2010, 4:51 AM

I am looking for GPL or other SPSS code to build charts of the sort displayed at the URL below (this
List serve does not allow pasting of graphics).

  https://www.radii.org/doc   click on  LIKERT STACKED BAR CHART.jpg

The Charts show responses for a set of Likert Scales, with the negative responses stacked to the left
of the origin and the positive responses stacked to the right.

The scale to both the left and right of the origin ranges from 0–100 (with the origin as zero).

Has anyone developed code for a chart such as this — or have suggestions of the best strategy to
approach the task.

=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@... (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