Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: graph combine of tabplot graphs: uncomparable bar heights

From   Nick Cox <>
To   "" <>
Subject   Re: st: graph combine of tabplot graphs: uncomparable bar heights
Date   Fri, 28 Jun 2013 13:40:21 +0100

Here's a dopey example to show the principle. By comparing the initial
graphs, we see that the highest bar on both graphs shows 30. So the
scale for the other graph (highest bar 27) must be adjusted relative
to that.

Note that the height to be used can be worked out by Stata on the fly:

`=0.8 * 27/30'

says "work out the result of 0.8 * 27/30 and use it".

sysuse auto, clear
tabplot foreign rep78 , showval

gen himpg = mpg > 30
label define himpg 1 ">30" 0 "<= 30"
label val himpg himpg
label var himpg "miles per gallon >30?"
tabplot himpg rep78 , showval

tabplot foreign rep78 , showval height(`=0.8 * 27/30') name(g1)
tabplot himpg rep78 , showval name(g2)
graph combine g1 g2, ycommon

On 28 June 2013 12:22, Nick Cox <> wrote:
> -tabplot- is from SSC. You are asked to explain where user-written
> programs you use come from.  Otherwise you waste the time of anyone
> who thinks "That sounds interesting" but then can't find -tabplot- on
> their system because it has not been installed. The small point of
> giving credit to whoever wrote it I leave on one side. This is all
> explained in the FAQ you were asked to read before posting.
> The underlying problem is that -tabplot- internally uses a scale that
> is only indirectly unrelated to the numbers being shown. In a case
> like
> sysuse auto
> tabplot foreign rep78 , showval
> the highest bar is drawn between y = 2 and y = 2.8. If the highest bar
> had been on the bottom row it would have been drawn between y = 1 and
> y = 1.8. This is regardless of what the highest bar represents. -graph
> combine- can only align x and y coordinates; it won't restructure the
> graphs internally. Similarly -yscale()- can have no effect here,
> because scaling has already taken place. In fact it could not be
> otherwise.
> Much of the effort of -tabplot- goes into using the space available as
> effectively as possible. The default is to leave 20% vertical space
> between the height of the tallest bar and the line above (or
> correspondingly if the bars are aligned horizontally).
> You have I think two choices. One is to choose a -height()- option
> separately for each graph so that the values come out as you want when
> you combine them.
> The second is to restructure your data, so that you use a -by()-
> option as well with -tabplot-. Then the bars in each panel will be
> drawn on the same scale.
> Nick
> On 28 June 2013 11:34, Brunelli Cinzia
> <>  [edited]
>>  I'm going to combine together in a single figure 3 graphs previously obtained with -tabplot- to show patients and physician agreement on the assessment of three different variables.
>> The syntax is the following
>> tabplot ecs_cp_q2 alberta_q0_imput, showval  percent xtitle("   " "   ") subtitle ("")  ///
>> ytitle("PHYSICIAN ASSESSMENT") title("INCIDENT PAIN", size(msmall)) saving(IP_AGREE, replace)
>> tabplot ecscp_neu pain_dtct_cat2, showval percent xtitle("   " "PATIENT ASSESSMENT") subtitle ("") ///
>> ytitle("") saving(NP_AGREE, replace) title("NEUROPATHIC PAIN ", size(msmall)) yscale(range(0 1))
>> tabplot ecs_cp_q3 any_dep_PHQ, showval  percent xtitle("   " "   ") subtitle ("") ///
>> ytitle("") saving(PD_AGREE, replace) title("PSYCHOLOGICAL DISTRESS", size(msmall))
>> graph combine  IP_AGREE.gph  NP_AGREE.gph PD_AGREE.gph,  col(3) ycommon xcommon
>> The commands work and the figure is nice but... proportions between bar heights are correct within each graph but not between graphs: i.e the fourth bar in the first graph, which represents 35% of the sample, is as tall as the first one in the second graph, which should represent 66% of the sample. I guess this has to do with different graphical formatting rules within each graph.
>> Is there a way to overcome this misrepresentation? I tried to use something like yscale(range(0 100)) in order to standardize yaxis scale, but it doesn't work. I find -tabplot- very useful for my proposal and it would be a pity not to be able to use it and present a "boring" table.

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index