Announcement

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

  • Controlling the range of the x-axis when combining two graphs with graph combine ..., xcommon?

    Is it possible to control the range of the x-axis when combining two graphs with graph combine ..., xcommon? The range of the x-variable (the limits of the intervals) in the data below is from -28 to 28. In the simple graph combine plot, the x-axes range from -30 to 30 which is fine. But when the option xcommon is selected, the range increases from -40 to 40. The data below are made up but in my original data, the large empty spaces in the figure make it difficult to detect any pattern.

    The code uses an undocumented feature of twoway bar to allow for varying bin-widths. I mention this, but I am not sure if this information is relevant here. See
    HTML Code:
    https://www.stata.com/support/faqs/graphics/histograms-with-varying-bin-widths/
    Code:
    clear
    input species binlim weight
    2 -28 34
    2 -24 34
    2 -20 34
    2 -8 24
    2 4 .
    5 -4 12
    5 4 13
    5 16 99
    5 20 55
    5 24 23
    5 28 .
    
    end
    twoway (bar weight binlim if species == 2, sort base(0) bartype(spanning)), legend(off) name(gs1, replace)
    twoway (bar weight binlim if species == 5, sort base(0) bartype(spanning)), legend(off) name(gs2, replace)
    graph close _all
    graph combine gs1 gs2, cols(1) xcommon
    graph combine gs1 gs2, cols(1)
    I am using Stata 17 on Windows 10.

    Click image for larger version

Name:	figure.png
Views:	1
Size:	19.3 KB
ID:	1647698

  • #2
    See https://www.statalist.org/forums/for...ed-xlab-values

    Comment


    • #3
      I would not use graph combine here. With some guesses at what you want, consider

      Code:
      clear
      input species binlim weight
      2 -28 34
      2 -24 34
      2 -20 34
      2 -8 24
      2 4 .
      5 -4 12
      5 4 13
      5 16 99
      5 20 55
      5 24 23
      5 28 .
      
      end
      twoway bar weight binlim, sort base(0) bartype(spanning) legend(off) by(species)
      
      gen whatever = binlim + 2 
      twoway bar weight whatever, blc(blue) bfc(none)  base(0) barw(4) by(species)

      Comment


      • #4
        Thanks Andrew. In the link you provided, you show how---with a re-scaling of the variable---we can shift the graph to the left and cover the white space there. Here, there are white spaces to the left and to the right so I am not sure if this would solve the problem. Could you elaborate?

        Also, the example in the link seems occur only with dates (see reply #3). This may somehow be relevant for undocumented feature I am using for graph bar, but I am not sure how.
        Last edited by Bert Breitenfelder; 01 Feb 2022, 06:28. Reason: Clarifying reply.

        Comment


        • #5
          Thanks Nick, I was not aware that the by-option can be used in this case. Thanks for pointing this out. This at least reduces the large white area on the left side.

          Comment

          Working...
          X