|
Please help me to plot this, if it is possible. Here is the data.
age height weight sexd_p 10 134 38.0 0 10 132 32.0 0 10 146 84.0 0 10 154 39.0 0 10 132 29.0 0 10 140 30.0 0 11 142 43.0 0 12 168 58.0 0 12 143 52.0 0 13 170 61.0 0 10 141 31.5 1 11 151 48.0 1 12 150 41.0 1 12 144 51.0 1 13 160 55.0 1 13 166 68.0 1 14 170 55.0 1 14 175 70.0 1 14 173 76.7 1 14 169 89.8 1 14 168 58.0 1 12 155 52.5 2 13 160 65.0 2 14 183 59.0 2 14 173 56.0 2 14 159 47.0 2 14 168 53.0 2 15 179 65.0 2 15 177 88.0 2 16 165 54.0 2 14 161 58.0 3 14 168 61.0 3 14 159 44.0 3 14 168 57.0 3 14 163 62.0 3 14 164 50.0 3 14 173 66.0 3 15 170 66.4 3 15 171 50.0 3 15 177 57.0 3 15 166 70.0 3 15 177 54.0 3 15 170 55.0 3 15 152 49.0 3 15 156 50.0 3 16 171 65.0 3 16 175 62.0 3 16 188 72.0 3 16 159 66.0 3 16 169 60.0 3 16 191 80.0 3 16 161 58.0 4 16 185 67.0 4 AGE is ordinal or scale SEXD_P (stage of sex development in pubic hairing) is ordinal HEIGHT and WEIGHT are scale. I need to plot AGE as X axis and SEXD_P as stacked area (For each age, this is the percent distribution of the stages summing to 100%). On the same graph, I want to add two lines, the dynamics of HEIGHT (mean for each age) and WEIGHT (same). Since height and weight are different units and scales of measurement I feel like giving dual Y axes: Y1 for HEIGHT, Y2 for WEIGHT. In other words, I want to combine graph: GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=age COUNT()[name="COUNT"] sexd_p MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: age=col(source(s), name("age"), unit.category()) DATA: COUNT=col(source(s), name("COUNT")) DATA: sexd_p=col(source(s), name("sexd_p"), unit.category()) GUIDE: axis(dim(1), label("Возраст")) GUIDE: axis(dim(2), label("Percent")) GUIDE: legend(aesthetic(aesthetic.color.interior), label("P - лобковое оволосение")) SCALE: cat(dim(1), include("10", "11", "12", "13", "14", "15", "16")) SCALE: linear(dim(2), include(0)) SCALE: cat(aesthetic(aesthetic.color.interior), include("0", "1", "2", "3", "4")) ELEMENT: area.stack(position(summary.percent(age*COUNT, base.coordinate(dim(1)))), color.interior(sexd_p), missing.wings()) END GPL. with graph GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=age MEAN(height)[name="MEAN_height"] MEAN(weight)[name="MEAN_weight"] MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: age=col(source(s), name("age"), unit.category()) DATA: MEAN_height=col(source(s), name("MEAN_height")) DATA: MEAN_weight=col(source(s), name("MEAN_weight")) GUIDE: axis(dim(1), label("Возраст")) GUIDE: axis(scale(y1), label("Mean Длина тела, см"), color(color."3E58AC")) GUIDE: axis(scale(y2), label("Mean Масса тела, кг"), color(color."2EB848"), opposite()) SCALE: cat(dim(1), include("10", "11", "12", "13", "14", "15", "16")) SCALE: y1 = linear(dim(2), include(0)) SCALE: y2 = linear(dim(2), include(0)) ELEMENT: line(position(age*MEAN_height), missing.wings(), color.interior(color."3E58AC"), scale(y1)) ELEMENT: line(position(age*MEAN_weight), missing.wings(), color.interior(color."2EB848"), scale(y2)) END GPL. I failed to combine. The problem is that both dual Y axes are occupied by HEIGHT and WEIGHT and so there no room for Y axis serving for the Area element. Even though I actually don't need that percent Y axis to be displayed, it seemingly is necessary as a gauge, and so there 3 Y axes in all - too many for GPL. Can you help to solve it? ===================== 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 |
|
I don't know whether it makes sense to show plots with three y axes. I was interested in a possible graph but could not find a solution using ggraph. Therefore I used a vector graphics program and copied the graphs (right mouse click - copy special - metafile) into the graphics program. I matched the size of the graphs, removed the percent y-axis of graph 1. Subsequently I superimposed the two graphs. This is the result:
GGraph_Example.pdf
It makes sense to produce a single graph but if you like to produce graphs like this regularly it is too time consuming ;-)
Cheers
Andreas
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 |
|
In reply to this post by Kirill Orlov
Here is your monstrosity Kirill,
<http://spssx-discussion.1045642.n5.nabble.com/file/t329824/Superimposed.png> ************************************************************************************************************************************. DATA LIST FREE / age (F2.0) height (F3.0) weight (F3.2) sexd_p (F1.0). BEGIN DATA 10 134 38.0 0 10 132 32.0 0 10 146 84.0 0 10 154 39.0 0 10 132 29.0 0 10 140 30.0 0 11 142 43.0 0 12 168 58.0 0 12 143 52.0 0 13 170 61.0 0 10 141 31.5 1 11 151 48.0 1 12 150 41.0 1 12 144 51.0 1 13 160 55.0 1 13 166 68.0 1 14 170 55.0 1 14 175 70.0 1 14 173 76.7 1 14 169 89.8 1 14 168 58.0 1 12 155 52.5 2 13 160 65.0 2 14 183 59.0 2 14 173 56.0 2 14 159 47.0 2 14 168 53.0 2 15 179 65.0 2 15 177 88.0 2 16 165 54.0 2 14 161 58.0 3 14 168 61.0 3 14 159 44.0 3 14 168 57.0 3 14 163 62.0 3 14 164 50.0 3 14 173 66.0 3 15 170 66.4 3 15 171 50.0 3 15 177 57.0 3 15 166 70.0 3 15 177 54.0 3 15 170 55.0 3 15 152 49.0 3 15 156 50.0 3 16 171 65.0 3 16 175 62.0 3 16 188 72.0 3 16 159 66.0 3 16 169 60.0 3 16 191 80.0 3 16 161 58.0 4 16 185 67.0 4 END DATA. DATASET NAME Phys. EXECUTE. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=age COUNT()[name="COUNT"] sexd_p MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: age=col(source(s), name("age"), unit.category()) DATA: COUNT=col(source(s), name("COUNT")) DATA: sexd_p=col(source(s), name("sexd_p"), unit.category()) GUIDE: axis(dim(1), label("Возраст")) GUIDE: axis(dim(2), label("Percent")) GUIDE: legend(aesthetic(aesthetic.color.interior), label("P - лобковое оволосение")) SCALE: cat(dim(1), include("10", "11", "12", "13", "14", "15", "16")) SCALE: linear(dim(2), include(0)) SCALE: cat(aesthetic(aesthetic.color.interior), include("0", "1", "2", "3", "4")) ELEMENT: area.stack(position(summary.percent(age*COUNT, base.coordinate(dim(1)))), color.interior(sexd_p), missing.wings()) END GPL. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=age MEAN(height)[name="MEAN_height"] MEAN(weight)[name="MEAN_weight"] MISSING=LISTWISE REPORTMISSING=NO /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: age=col(source(s), name("age"), unit.category()) DATA: MEAN_height=col(source(s), name("MEAN_height")) DATA: MEAN_weight=col(source(s), name("MEAN_weight")) GUIDE: axis(dim(1), label("Возраст")) GUIDE: axis(scale(y1), label("Mean Длина тела, см"), color(color."3E58AC")) GUIDE: axis(scale(y2), label("Mean Масса тела, кг"), color(color."2EB848"), opposite()) SCALE: cat(dim(1), include("10", "11", "12", "13", "14", "15", "16")) SCALE: y1 = linear(dim(2), include(0)) SCALE: y2 = linear(dim(2), include(0)) ELEMENT: line(position(age*MEAN_height), missing.wings(), color.interior(color."3E58AC"), scale(y1)) ELEMENT: line(position(age*MEAN_weight), missing.wings(), color.interior(color."2EB848"), scale(y2)) END GPL. *Putting the two together. COMPUTE sexd_p = sexd_p + 1. VECTOR SDum(5,F1.0). COMPUTE SDum(sexd_p) = 1. EXECUTE. DATASET DECLARE Agg. AGGREGATE OUTFILE='Agg' /BREAK age /SDum1 TO SDum5 = SUM(SDum1 TO SDum5) /height = MEAN(height) /weight = MEAN(weight). DATASET ACTIVATE Agg. RECODE SDum1 TO SDum5 (SYSMIS = 0). VARSTOCASES /MAKE CountSex FROM SDum1 TO SDum5 /INDEX sexd_p. COMPUTE sexd_p = sexd_p - 1. AGGREGATE OUTFILE=* MODE=ADDVARIABLES /BREAK Age /TotalSex = SUM(CountSex). COMPUTE PropSex = CountSex/TotalSex. *Need to put proportion of total within each category relative to some external value. *Here just choose 200. COMPUTE RelSex = PropSex*200. FORMATS Height Weight RelSex (F3.0). DO IF age = LAG(age). COMPUTE height = $SYSMIS. COMPUTE weight = $SYSMIS. END IF. EXECUTE. *Now putting all of these onto one chart. GGRAPH /GRAPHDATASET NAME="graphdataset" VARIABLES=age height weight PropSex sexd_p MISSING=VARIABLEWISE /GRAPHSPEC SOURCE=INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: age=col(source(s), name("age"), unit.category()) DATA: height=col(source(s), name("height")) DATA: weight=col(source(s), name("weight")) DATA: sexd_p=col(source(s), name("sexd_p"), unit.category()) DATA: PropSex=col(source(s), name("PropSex")) TRANS: RelSex = eval(PropSex*200) GUIDE: axis(dim(1), label("Возраст")) GUIDE: axis(scale(y1), label("Mean Длина тела, см"), color(color."3E58AC")) GUIDE: axis(scale(y2), label("Mean Масса тела, кг"), color(color."2EB848"), opposite()) SCALE: cat(dim(1), include("10", "11", "12", "13", "14", "15", "16")) SCALE: y1 = linear(dim(2), include(0), max(200)) SCALE: y2 = linear(dim(2), include(0)) ELEMENT: area.stack(position(age*RelSex), color.interior(sexd_p), missing.gap(), scale(y1)) ELEMENT: line(position(age*height), missing.wings(), color.interior(color."3E58AC"), scale(y1)) ELEMENT: line(position(age*weight), missing.wings(), color.interior(color."2EB848"), scale(y2)) END GPL. ************************************************************************************************************************************. ----- Andy W [hidden email] http://andrewpwheeler.wordpress.com/ -- Sent from: http://spssx-discussion.1045642.n5.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 |
|
Andy, thank you very much for the help and forgive please
for stealing your time. My request was indeed monstrosity, I admit
it!
15.05.2018 18:23, Andy W пишет:
Here is your monstrosity Kirill, <http://spssx-discussion.1045642.n5.nabble.com/file/t329824/Superimposed.png> ===================== 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 reply to this post by Andy W
Another possibility is to use multiple graphs, to get a second axis to the
right of the graph, explaining the proportions (I, too, agree on the difficulty on interpreting the graph). With this solution there is no need to rescale the proportions. In this example the secondary graph is empty, just forcing the display of the axis. It is the width of the graph area that moves the axis. The only post-production touch-up is to move the Color Legend Box more to the right. The placement fits, IMHO, as the color scale is related to the stacked area graph. /PR <http://spssx-discussion.1045642.n5.nabble.com/file/t339873/CombinedGraphs.png> GGRAPH /GRAPHDATASET NAME = "graphdataset" VARIABLES = age height weight PropSex sexd_p MISSING = VARIABLEWISE /GRAPHSPEC SOURCE = INLINE. BEGIN GPL SOURCE: s=userSource(id("graphdataset")) DATA: age =col(source(s), name("age")) DATA: height =col(source(s), name("height")) DATA: weight =col(source(s), name("weight")) DATA: sexd_p =col(source(s), name("sexd_p"), unit.category()) DATA: PropSex=col(source(s), name("PropSex")) TRANS: RelSex =eval(PropSex*100) TRANS: Zero =eval(0) GRAPH: begin(origin(8%, 10%), scale(58%, 80%)) GUIDE: axis(dim(1) ,label("Age (yr)") ) GUIDE: axis(scale(y1) ,label("Height (cm)") ,delta(10) ,color(color."8c2d04") ) GUIDE: axis(scale(y2) ,label("Weight (kg)") ,delta(5) ,color(color."d94801") ,opposite() ) GUIDE: axis(scale(y3) ,label("%") ,delta(10) ,color(color.red) ,opposite() ,null() ) GUIDE: legend(aesthetic(aesthetic.color.interior) ,label("Sexual development") ) SCALE: cat(aesthetic(aesthetic.color.interior) ,include("0", "1", "2", "3", "4") ,map(("0",color."feedde") ,("1",color."fdd0a2") ,("2",color."fdae6b") ,("3",color."fd8d3c") ,("4",color."f16913") ,("5",color."d94801") ,("6",color."8c2d04") ) ) SCALE: linear(dim(1) ) SCALE: y1 = linear(dim(2) ,include(0) ,max(200) ) SCALE: y2 = linear(dim(2) ,include(0) ) SCALE: y3 = linear(dim(2) ,include(0) ,max(100) ) ELEMENT: area.stack(position(age*RelSex) ,color.interior(sexd_p) ,missing.gap() ,scale(y3) ) ELEMENT: line(position(age*height) ,missing.wings() ,color.interior(color."8c2d04") ,scale(y1) ) ELEMENT: line(position(age*weight) ,missing.wings() ,color.interior(color."d94801") ,scale(y2) ) GRAPH: end() GRAPH: begin(origin(8%, 10%), scale(67%, 80%)) GUIDE: axis(dim(1) ,label("Age (yr)") ,null() ) GUIDE: axis(scale(y3) ,label("Percent") ,delta(10) ,color(color.red) ,opposite() ) GUIDE: legend(aesthetic(aesthetic.color.interior) ,null() ) SCALE: linear(dim(1) ) SCALE: y3 = linear(dim(2) ,include(0) ,max(100) ) ELEMENT: area.stack(position(Zero*Zero) ,color.interior(sexd_p) ,missing.gap() ,scale(y3) ) GRAPH: end() END GPL. -- Sent from: http://spssx-discussion.1045642.n5.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 |
|
PRogman, Andreas,
Thank you much for your answers. Both your answers were helpful, as Andrew's answer was. 16.05.2018 15:05, PRogman пишет:
===================== 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 REFCARDAnother possibility is to use multiple graphs, to get a second axis to the right of the graph, explaining the proportions (I, too, agree on the difficulty on interpreting the graph). With this solution there is no need to rescale the proportions. In this example the secondary graph is empty, just forcing the display of the axis. It is the width of the graph area that moves the axis. The only post-production touch-up is to move the Color Legend Box more to the right. The placement fits, IMHO, as the color scale is related to the stacked area graph. /PR <http://spssx-discussion.1045642.n5.nabble.com/file/t339873/CombinedGraphs.png> |
| Free forum by Nabble | Edit this page |
