Announcement

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

  • How to change the width of bars in a catplot graph

    Hello everyone,

    I generated a bar graph using the catplot command for two categorical variables and I want to change the width of the bars showing. I tried with the graph editor but i couldn't manage. Any ideas?

    I am using the following code:

    catplot Variable1 Variable2, percent(Variable2) blabel(bar, position(inside) color(white) format(%8.0f)) asyvars

    Thanks in advance.

  • #2
    catplot is from SSC, authored by Nick Cox. Use the option -var#opts(gap(*#))- where the 1st hash references the variable order and the second hash the gap (0= no gap), e.g.,.

    Code:
    catplot Variable1 Variable2, var1opts(gap(*0.1))  var2opts(gap(*0.1))

    Comment


    • #3
      Ok, but how to control the thickness of the bars?

      Comment


      • #4
        Nick Cox , as you are the mastermind behind this 'life-saving' command for my purposes. Can you please advice?

        Comment


        • #5
          Andrew Musau has already explained the principle. His example showed how to shrink the gaps.

          More generally, catplot is just a wrapper for graph hbar or graph bar in this context, so you need to reach through to either command -- really, it is the same code -- if an option of catplot is not obviously relevant.

          So, as another example, increase the gaps between the bars -- and the bars must get thinner.

          Code:
          sysuse auto, clear 
          catplot foreign rep78 
          catplot foreign rep78, var1opts(gap(*10))

          Comment

          Working...
          X