|
I would like to modify a stacked bar chart to present some survey data so that the percent of positive responses is on the right side of the origin and the percent of negative or neutral responses is on the left side. Both sides will originate from the center at 0%. Below is my example data and a starting point for my GPL code. I am new to GPL and am lost on how to do this. Any ideas on how I can split the graph?
Thank you for your help, Jim ------------- DATA LIST LIST/ customer_id question_number responses (F4, F2, A30). BEGIN DATA 1234 1 '4 - agree' 4567 1 '3 - neutral' 7891 1 '2 - disagree' 2345 1 '3 - neutral' 6751 1 '2 - disagree' 9521 1 '3 - neutral' 7415 1 '2 - disagree' 2651 1 '5 - strongly agree' 4152 1 '3 - neutral' 3655 1 '2 - disagree' 2587 1 '3 - neutral' 4125 1 '4 - agree' 3658 1 '3 - neutral' 4157 1 '1 - strongly disagree' 2541 1 '3 - neutral' 8521 1 '4 - agree' 9514 1 '4 - agree' 4125 1 '4 - agree' 3652 1 '3 - neutral' 8569 1 '1 - strongly disagree' 1234 2 '3 - neutral' 4567 2 '2 - disagree' 7891 2 '3 - neutral' 2345 2 '4 - agree' 6751 2 '3 - neutral' 9521 2 '1 - strongly disagree' 7415 2 '3 - neutral' 2651 2 '4 - agree' 4152 2 '5 - strongly agree' 3655 2 '4 - agree' 2587 2 '3 - neutral' 4125 2 '2 - disagree' 3658 2 '2 - disagree' 4157 2 '3 - neutral' 2541 2 '2 - disagree' 8521 2 '3 - neutral' 9514 2 '2 - disagree' 4125 2 '3 - neutral' 3652 2 '2 - disagree' 8569 2 '3 - neutral' 1234 3 '4 - agree' 4567 3 '3 - neutral' 7891 3 '2 - disagree' 2345 3 '3 - neutral' 6751 3 '4 - agree' 9521 3 '3 - neutral' 7415 3 '2 - disagree' 2651 3 '3 - neutral' 4152 3 '5 - strongly agree' 3655 3 '4 - agree' 2587 3 '3 - neutral' 4125 3 '4 - agree' 3658 3 '5 - strongly agree' 4157 3 '3 - neutral' 2541 3 '4 - agree' 8521 3 '5 - strongly agree' 9514 3 '2 - disagree' 4125 3 '1 - strongly disagree' 3652 3 '2 - disagree' 8569 3 '3 - neutral' 1234 4 '3 - neutral' 4567 4 '2 - disagree' 7891 4 '3 - neutral' 2345 4 '4 - agree' 6751 4 '3 - neutral' 9521 4 '1 - strongly disagree' 7415 4 '3 - neutral' 2651 4 '4 - agree' 4152 4 '4 - agree' 3655 4 '4 - agree' 2587 4 '3 - neutral' 4125 4 '1 - strongly disagree' 3658 4 '3 - neutral' 4157 4 '2 - disagree' 2541 4 '5 - strongly agree' 8521 4 '3 - neutral' 9514 4 '2 - disagree' 4125 4 '3 - neutral' 3652 4 '4 - agree' 8569 4 '3 - neutral' END DATA. * Chart Builder. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=question_number COUNT()[name="COUNT"] responses MISSING=VARIABLEWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: question_number=col(source(s), name("question_number"), unit.category()) DATA: COUNT=col(source(s), name("COUNT")) DATA: responses=col(source(s), name("responses"), unit.category()) COORD: rect(dim(1,2), transpose()) GUIDE: axis(dim(1), label("Question Number")) GUIDE: axis(dim(2), label("Percent")) GUIDE: legend(aesthetic(aesthetic.color.interior), label("Responses")) SCALE: cat(dim(1), reverse()) SCALE: linear(dim(2), include(0)) SCALE: cat(aesthetic(aesthetic.color.interior), include("1 - strongly disagree", "2 - disagree", "3 - neutral", "4 - agree", "5 - strongly agree"), reverse(), aestheticMissing(color.black)) ELEMENT: interval.stack(position(summary.percent(question_number*COUNT, base.coordinate(dim(1)))), color.interior(responses), shape.interior(shape.square)) END GPL. ===================== 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 |
|
Think of this as a population pyramid chart. You're going to have to recode
provide a splitter variable by recoding your response variable into a binary variable with positive values set to one category and negative to another and neutral set to missing. Give that you've got a long string variable here to represent your value, it's simpler to just use AUTORECODE to get a variable with values 1 to 5 and then recode from there. The following replaces your GGRAPH code: AUTORECODE VARIABLES=responses /INTO respval /PRINT. recode respval (1, 2=1)(3,4=2) into resplit. missing values resplit (3). value labels resplit 1 "Negative" 2 "Positive". variable labels resplit "Dichtomized Response". * Chart Builder. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=COUNT()[name="COUNT"] question_number resplit[LEVEL=NOMINAL] MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: COUNT=col(source(s), name("COUNT")) DATA: question_number=col(source(s), name("question_number"), unit.category()) DATA: resplit=col(source(s), name("resplit"), unit.category()) COORD: transpose(mirror(rect(dim(1,2)))) GUIDE: axis(dim(1), opposite(), label("Question Number")) GUIDE: axis(dim(2), label("Percent")) GUIDE: axis(dim(3), label("Response"), opposite(), gap(0px)) GUIDE: legend(aesthetic(aesthetic.color), null()) SCALE: cat(dim(1), reverse()) SCALE: linear(dim(2), include(0)) SCALE: cat(dim(3), include("1.00", "2.00")) ELEMENT: interval(position(summary.percent(question_number*COUNT*resplit, base.all(acrossPanels()))), color.interior(resplit), label(COUNT)) END GPL. Notes: Note the use of the mirror function to create mirrored values on the COORD statement. A population pyramid uses panels rather than clustering. This requires a different percentage base to get the right percents. I've added a label of the actual counts to the bars because relying upon percents with that middle category out might be misleading. Chart Builder generates population pyramids but doesn't provide the percentage option. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of James Phillips Sent: Wednesday, December 03, 2008 11:14 AM To: [hidden email] Subject: How do I modify a stacked bar chart to give it a pyramid-like look? I would like to modify a stacked bar chart to present some survey data so that the percent of positive responses is on the right side of the origin and the percent of negative or neutral responses is on the left side. Both sides will originate from the center at 0%. Below is my example data and a starting point for my GPL code. I am new to GPL and am lost on how to do this. Any ideas on how I can split the graph? Thank you for your help, Jim ------------- DATA LIST LIST/ customer_id question_number responses (F4, F2, A30). BEGIN DATA 1234 1 '4 - agree' 4567 1 '3 - neutral' 7891 1 '2 - disagree' 2345 1 '3 - neutral' 6751 1 '2 - disagree' 9521 1 '3 - neutral' 7415 1 '2 - disagree' 2651 1 '5 - strongly agree' 4152 1 '3 - neutral' 3655 1 '2 - disagree' 2587 1 '3 - neutral' 4125 1 '4 - agree' 3658 1 '3 - neutral' 4157 1 '1 - strongly disagree' 2541 1 '3 - neutral' 8521 1 '4 - agree' 9514 1 '4 - agree' 4125 1 '4 - agree' 3652 1 '3 - neutral' 8569 1 '1 - strongly disagree' 1234 2 '3 - neutral' 4567 2 '2 - disagree' 7891 2 '3 - neutral' 2345 2 '4 - agree' 6751 2 '3 - neutral' 9521 2 '1 - strongly disagree' 7415 2 '3 - neutral' 2651 2 '4 - agree' 4152 2 '5 - strongly agree' 3655 2 '4 - agree' 2587 2 '3 - neutral' 4125 2 '2 - disagree' 3658 2 '2 - disagree' 4157 2 '3 - neutral' 2541 2 '2 - disagree' 8521 2 '3 - neutral' 9514 2 '2 - disagree' 4125 2 '3 - neutral' 3652 2 '2 - disagree' 8569 2 '3 - neutral' 1234 3 '4 - agree' 4567 3 '3 - neutral' 7891 3 '2 - disagree' 2345 3 '3 - neutral' 6751 3 '4 - agree' 9521 3 '3 - neutral' 7415 3 '2 - disagree' 2651 3 '3 - neutral' 4152 3 '5 - strongly agree' 3655 3 '4 - agree' 2587 3 '3 - neutral' 4125 3 '4 - agree' 3658 3 '5 - strongly agree' 4157 3 '3 - neutral' 2541 3 '4 - agree' 8521 3 '5 - strongly agree' 9514 3 '2 - disagree' 4125 3 '1 - strongly disagree' 3652 3 '2 - disagree' 8569 3 '3 - neutral' 1234 4 '3 - neutral' 4567 4 '2 - disagree' 7891 4 '3 - neutral' 2345 4 '4 - agree' 6751 4 '3 - neutral' 9521 4 '1 - strongly disagree' 7415 4 '3 - neutral' 2651 4 '4 - agree' 4152 4 '4 - agree' 3655 4 '4 - agree' 2587 4 '3 - neutral' 4125 4 '1 - strongly disagree' 3658 4 '3 - neutral' 4157 4 '2 - disagree' 2541 4 '5 - strongly agree' 8521 4 '3 - neutral' 9514 4 '2 - disagree' 4125 4 '3 - neutral' 3652 4 '4 - agree' 8569 4 '3 - neutral' END DATA. * Chart Builder. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=question_number COUNT()[name="COUNT"] responses MISSING=VARIABLEWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: question_number=col(source(s), name("question_number"), unit.category()) DATA: COUNT=col(source(s), name("COUNT")) DATA: responses=col(source(s), name("responses"), unit.category()) COORD: rect(dim(1,2), transpose()) GUIDE: axis(dim(1), label("Question Number")) GUIDE: axis(dim(2), label("Percent")) GUIDE: legend(aesthetic(aesthetic.color.interior), label("Responses")) SCALE: cat(dim(1), reverse()) SCALE: linear(dim(2), include(0)) SCALE: cat(aesthetic(aesthetic.color.interior), include("1 - strongly disagree", "2 - disagree", "3 - neutral", "4 - agree", "5 - strongly agree"), reverse(), aestheticMissing(color.black)) ELEMENT: interval.stack(position(summary.percent(question_number*COUNT, base.coordinate(dim(1)))), color.interior(responses), shape.interior(shape.square)) END GPL. ===================== 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 |
| Free forum by Nabble | Edit this page |
