Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is there a way to decrease the distance between bars in tabplot?

    Hello there

    any help would be greatly appreciated. My data looks something like this and I would be really happy if I could reduce the gap between the bars. However
    Code:
    bargap(#)
    seems not to work if placed among the other tablet options. Help tabplot didn't seem to bring me there.

    I need a rather "low" plot, so I would wish that after .3 (after the label) the new bar starts. Bars should be much closer towards each other.
    Is there any way to achieve this?

    Here is example code:
    Code:
     sysuse auto
    
    gen onetwotree = 1 if rep78 <= 2
    replace onetwotree = 2 if rep78 == 3 | rep78 == 4
    replace onetwotree = 3 if rep78 >= 5
    
    tabplot onetwotree foreign  , percent(foreign) showval(offset(.2) mlabp(3)) horizontal  barwidth(.1) ///
     subtitle("% of foreign", size(small)) xtitle("") bfcolor(none)

    Thank you very much!

    Edit: I forgot to mention I use Stata 15.
    Last edited by Gracia Brueckmann; 14 Jul 2020, 06:16. Reason: Edit: I forgot to mention I use Stata 15.

  • #2
    tabplot is from Stata Journal, authored by Nick Cox. I guess how you perceive distance depends on the axis scale, which you can control. Otherwise, see

    Code:
    help aspect ratio
    Code:
    tabplot onetwotree foreign  , percent(foreign) showval(offset(.2) mlabp(3)) horizontal  barwidth(.1) ///
    subtitle("% of foreign", size(small)) xtitle("") bfcolor(none)
    gr save gr1, replace
    
    tabplot onetwotree foreign  , percent(foreign) showval(offset(.2) mlabp(3)) horizontal  barwidth(.1) ///
    subtitle("% of foreign", size(small)) xtitle("") bfcolor(none) ysc(r(-0.5 3.5))
    gr save gr2, replace
    
    gr combine gr1.gph gr2.gph
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	28.5 KB
ID:	1563376

    Comment


    • #3
      Hello Gracia. I don't know how to achieve what you want using -tabplot-. But you could try this as an alternative:

      Code:
      graph bar, over(onetwotree) by(foreign) blabel(total,format(%5.2f)) ///
      ytitle(Percent within Domestic/Foreign category)
      --
      Bruce Weaver
      Email: [email protected]
      Version: Stata/MP 18.5 (Windows)

      Comment


      • #4
        tabplot is community-contributed and from the Stata Journal. An update is in press for issue 20(3): 2020. However, the answer is nothing to do with tabplot as such.

        But first note that, as documented, tabplot is a wrapper for twoway rbar and (as such -- this is indeed likely to be confusing to beginners) is nothing to do with graph bar. Hence options of the latter will not apply.

        As you have reduced the barwidth, you have thereby increased the gap between bars. What remains, so far as I can see, is to change the size or shape of the graph using
        ysize(), xsize(), or aspect() options.

        Comment


        • #5
          Allright, thank you all very much. I found out, for my case a
          Code:
          fysize(25)
          option does the trick, as I later use it in a combined graph.

          Thanks for clarifying the difference between two-way bar and graph bar. I had no idea.

          Comment

          Working...
          X