|
I found a bar chart in a book and the percentages were printed on the bar charts directly.
Is there a way to do this in spss? Thank you Rongjin Guan Below is a link to the bar chart: http://tinypic.com/r/16l9sw8/9 ===================== 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 |
|
In the chart editor you can go to Elements -> Show Data Labels and it will place the data labels in the chart. You can then edit the format and choose where you want them (top, middle, bottom) or move them manually.
In syntax it depends on how the chart is made. If it is made via aggregation it is more difficult in code to add them in - it takes a few extra steps. Some examples below. *************************************************. DATA LIST FREE / X. BEGIN DATA 1 2 2 3 3 3 END DATA. *Default bar chart in GGRAPH using aggregate commands. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=X COUNT()[name="COUNT"] MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: X=col(source(s), name("X"), unit.category()) DATA: COUNT=col(source(s), name("COUNT")) GUIDE: axis(dim(1), label("X")) GUIDE: axis(dim(2), label("Percent")) SCALE: linear(dim(2), include(0)) ELEMENT: interval(position(summary.percent(X*COUNT, base.all(acrossPanels()))), shape.interior(shape.square)) END GPL. *Add in total N, and then make percents. AGGREGATE OUTFILE=* MODE=ADDVARIABLES /BREAK /TotN = N. AGGREGATE OUTFILE=* MODE=ADDVARIABLES /BREAK X /CatN = N. COMPUTE Perc = (CatN/TotN)*100. FORMATS Perc (F3.0). GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=X COUNT()[name="COUNT"] MAXIMUM(Perc)[name="Perc"] /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: X=col(source(s), name("X"), unit.category()) DATA: COUNT=col(source(s), name("COUNT")) DATA: Perc=col(source(s), name("Perc")) GUIDE: axis(dim(1), label("X")) GUIDE: axis(dim(2), label("Percent")) SCALE: linear(dim(2), include(0)) ELEMENT: interval(position(summary.percent(X*COUNT, base.all(acrossPanels()))), shape.interior(shape.square), label(Perc)) END GPL. *Can set the location alittle above the bars if you want. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=X COUNT()[name="COUNT"] MAXIMUM(Perc)[name="Perc"] /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: X=col(source(s), name("X"), unit.category()) DATA: COUNT=col(source(s), name("COUNT")) DATA: Perc=col(source(s), name("Perc")) TRANS: PercP = eval(Perc + 1) GUIDE: axis(dim(1), label("X")) GUIDE: axis(dim(2), label("Percent")) SCALE: linear(dim(2), include(0)) ELEMENT: interval(position(summary.percent(X*COUNT, base.all(acrossPanels()))), shape.interior(shape.square)) ELEMENT: point(position(X*PercP), transparency.exterior(transparency."1"), label(Perc)) END GPL. *Or use TRANS inline with the TotN variable you created - above can set the formats nicer though. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=X COUNT()[name="COUNT"] MAXIMUM(TotN)[name="TotN"] /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: X=col(source(s), name("X"), unit.category()) DATA: COUNT=col(source(s), name("COUNT")) DATA: TotN=col(source(s), name("TotN")) TRANS: Per = eval(100*COUNT/TotN) GUIDE: axis(dim(1), label("X")) GUIDE: axis(dim(2), label("Percent")) SCALE: linear(dim(2), include(0)) ELEMENT: interval(position(summary.percent(X*COUNT, base.all(acrossPanels()))), shape.interior(shape.square), label(Per)) END GPL. *************************************************. |
|
Thank you. I will give it a try.
Rongjin ________________________________________ From: SPSSX(r) Discussion [[hidden email]] On Behalf Of Andy W [[hidden email]] Sent: Tuesday, March 15, 2016 7:53 AM To: [hidden email] Subject: Re: how to display the percentage in bar chart In the chart editor you can go to Elements -> Show Data Labels and it will place the data labels in the chart. You can then edit the format and choose where you want them (top, middle, bottom) or move them manually. In syntax it depends on how the chart is made. If it is made via aggregation it is more difficult in code to add them in - it takes a few extra steps. Some examples below. *************************************************. DATA LIST FREE / X. BEGIN DATA 1 2 2 3 3 3 END DATA. *Default bar chart in GGRAPH using aggregate commands. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=X COUNT()[name="COUNT"] MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: X=col(source(s), name("X"), unit.category()) DATA: COUNT=col(source(s), name("COUNT")) GUIDE: axis(dim(1), label("X")) GUIDE: axis(dim(2), label("Percent")) SCALE: linear(dim(2), include(0)) ELEMENT: interval(position(summary.percent(X*COUNT, base.all(acrossPanels()))), shape.interior(shape.square)) END GPL. *Add in total N, and then make percents. AGGREGATE OUTFILE=* MODE=ADDVARIABLES /BREAK /TotN = N. AGGREGATE OUTFILE=* MODE=ADDVARIABLES /BREAK X /CatN = N. COMPUTE Perc = (CatN/TotN)*100. FORMATS Perc (F3.0). GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=X COUNT()[name="COUNT"] MAXIMUM(Perc)[name="Perc"] /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: X=col(source(s), name("X"), unit.category()) DATA: COUNT=col(source(s), name("COUNT")) DATA: Perc=col(source(s), name("Perc")) GUIDE: axis(dim(1), label("X")) GUIDE: axis(dim(2), label("Percent")) SCALE: linear(dim(2), include(0)) ELEMENT: interval(position(summary.percent(X*COUNT, base.all(acrossPanels()))), shape.interior(shape.square), label(Perc)) END GPL. *Can set the location alittle above the bars if you want. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=X COUNT()[name="COUNT"] MAXIMUM(Perc)[name="Perc"] /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: X=col(source(s), name("X"), unit.category()) DATA: COUNT=col(source(s), name("COUNT")) DATA: Perc=col(source(s), name("Perc")) TRANS: PercP = eval(Perc + 1) GUIDE: axis(dim(1), label("X")) GUIDE: axis(dim(2), label("Percent")) SCALE: linear(dim(2), include(0)) ELEMENT: interval(position(summary.percent(X*COUNT, base.all(acrossPanels()))), shape.interior(shape.square)) ELEMENT: point(position(X*PercP), transparency.exterior(transparency."1"), label(Perc)) END GPL. *Or use TRANS inline with the TotN variable you created - above can set the formats nicer though. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=X COUNT()[name="COUNT"] MAXIMUM(TotN)[name="TotN"] /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: X=col(source(s), name("X"), unit.category()) DATA: COUNT=col(source(s), name("COUNT")) DATA: TotN=col(source(s), name("TotN")) TRANS: Per = eval(100*COUNT/TotN) GUIDE: axis(dim(1), label("X")) GUIDE: axis(dim(2), label("Percent")) SCALE: linear(dim(2), include(0)) ELEMENT: interval(position(summary.percent(X*COUNT, base.all(acrossPanels()))), shape.interior(shape.square), label(Per)) END GPL. *************************************************. ----- Andy W [hidden email] http://andrewpwheeler.wordpress.com/ -- View this message in context: http://spssx-discussion.1045642.n5.nabble.com/how-to-display-the-percentage-in-bar-chart-tp5731743p5731744.html Sent from the SPSSX Discussion mailing list archive at Nabble.com. ===================== 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 |
