Dear All,
I am looking for a way to control the legend and axis labels to result in a particular illustration. Consider the following example.

The number and numbering of m* variables can vary (I can't assume they always start from 1, or that there are no gaps in numbering, etc). If that matters, they are resulting from a reshape command.
The graph that I want is shown in G4. A straightforward graphing (panel G1) has two problems:
1) legend entries are not variable labels.
2) axis values do not obey the format of the variable.
(G2 and G3 show some intermediate steps)
Following the [excellent] book of Mitchell (ISBN 9781881228851) , I have tried the nolabel option (panel G2) to avoid the "means of .." text. Unfortunately, there seems to be no option to force the variable labels to be put into the legend (which seems to be the most natural way, and all the other modes can be implemented from there, assigning e.g. variable names as the variable labels). I would like to avoid code-generating code (code that expands m* into a variable list, then inspects variables one after another constructing the options list, which are then passed to graph bar). This is quite similar to the recently discussed issue , but not exactly the same, as this current issue is probably simpler, and I have a feeling that there's got to be a standard option for it. Panel G3 shows the result of what would be the result of that self-assembled code. My feeling is that the graph bar uses collapse inside, which destroys the original variable labels with some statistics, hence no option will resurrect them, but wanted to ask just in case.
Finally the panel G4 tries to compensate for ignoring the format of the value of the axis. Again, I believe that the format of the label should coincide to the original format of the variable, but no, it is ignored and some default format is used. I have tried to specify the format as part of the over option in panel G3, but it is ignored without any effect or error message. G4 relies on a totally reliable, but imho totally unnecessary workaround with generating a string variable utilizing the format of the variable, and supplying the string as the category instead.
I am looking for a simpler way to build G4.
Thank you, Sergiy Radyakin
I am looking for a way to control the legend and axis labels to result in a particular illustration. Consider the following example.
Code:
clear all input day m9 m12 m17 20001 10 20 5 20002 10 15 7 20003 12 18 0 end format day %td label variable m9 "Damaged beyond restoration" label variable m12 "Lost or stolen" label variable m17 "Status unknown" // ---- end of data setup ----------------------------------------------------- graph bar m*, over(day) stack legend(rows(1)) xsize(3) ysize(2) name(G1) title(G1) graph bar m*, over(day) stack legend(rows(1)) xsize(3) ysize(2) name(G2) title(G2) nolabel graph bar m*, over(day, label(format("%td"))) stack legend(rows(1)) xsize(3) ysize(2) title(G3) /// legend( label(1 "`:variable label m9'") /// label(2 "`:variable label m12'") /// label(3 "`:variable label m17'")) name(G3) generate date=string(day,"%td") // workaround to force a particular label graph bar m*, over(date) stack legend(rows(1)) xsize(3) ysize(2) title(G4) /// legend( label(1 "`:variable label m9'") /// label(2 "`:variable label m12'") /// label(3 "`:variable label m17'")) name(G4) graph combine G1 G2 G3 G4, cols(2) ysize(6) xsize(8) scale(0.5) // ---- end of example --------------------------------------------------------
The number and numbering of m* variables can vary (I can't assume they always start from 1, or that there are no gaps in numbering, etc). If that matters, they are resulting from a reshape command.
The graph that I want is shown in G4. A straightforward graphing (panel G1) has two problems:
1) legend entries are not variable labels.
2) axis values do not obey the format of the variable.
(G2 and G3 show some intermediate steps)
Following the [excellent] book of Mitchell (ISBN 9781881228851) , I have tried the nolabel option (panel G2) to avoid the "means of .." text. Unfortunately, there seems to be no option to force the variable labels to be put into the legend (which seems to be the most natural way, and all the other modes can be implemented from there, assigning e.g. variable names as the variable labels). I would like to avoid code-generating code (code that expands m* into a variable list, then inspects variables one after another constructing the options list, which are then passed to graph bar). This is quite similar to the recently discussed issue , but not exactly the same, as this current issue is probably simpler, and I have a feeling that there's got to be a standard option for it. Panel G3 shows the result of what would be the result of that self-assembled code. My feeling is that the graph bar uses collapse inside, which destroys the original variable labels with some statistics, hence no option will resurrect them, but wanted to ask just in case.
Finally the panel G4 tries to compensate for ignoring the format of the value of the axis. Again, I believe that the format of the label should coincide to the original format of the variable, but no, it is ignored and some default format is used. I have tried to specify the format as part of the over option in panel G3, but it is ignored without any effect or error message. G4 relies on a totally reliable, but imho totally unnecessary workaround with generating a string variable utilizing the format of the variable, and supplying the string as the category instead.
I am looking for a simpler way to build G4.
Thank you, Sergiy Radyakin
Comment