Announcement

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

  • Equivalent to nofill option in tabplot?

    I need to create a graph with two panels and a common y axis. I'm using Stata version 16.1. The user-contributed command -tabplot- (ssc, by Nick Cox) gets me very close to what I want:


    Click image for larger version

Name:	Graphs.png
Views:	1
Size:	24.8 KB
ID:	1671957



    From here I would like to:

    a) give each panel a different x-axis, rather than showing blank spaces where there are no values;

    b) remove the note "Graphs by period" at the bottom (I can do it through the Graph Editor, but can it be done directly when creating the graph?)

    Here are the data and code for the image above:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(country freq) str9 years float period
    1  400 "1990-1995" 1
    1  308 "1995-2000" 1
    1  418 "2005-2010" 2
    1  679 "2010-2015" 2
    2  490 "1990-1995" 1
    2   54 "1995-2000" 1
    2 -174 "2005-2010" 2
    2 -530 "2010-2015" 2
    3 -491 "1990-1995" 1
    3   50 "1995-2000" 1
    3  107 "2005-2010" 2
    3  858 "2010-2015" 2
    4 -221 "1990-1995" 1
    4 -141 "1995-2000" 1
    4 -359 "2005-2010" 2
    4  498 "2010-2015" 2
    5 -220 "1990-1995" 1
    5  925 "1995-2000" 1
    5  648 "2005-2010" 2
    5  514 "2010-2015" 2
    6   28 "1990-1995" 1
    6  229 "1995-2000" 1
    6 -184 "2005-2010" 2
    6  320 "2010-2015" 2
    7   44 "1990-1995" 1
    7  907 "1995-2000" 1
    7 -316 "2005-2010" 2
    7 -234 "2010-2015" 2
    end
    label values country co
    label def co 1 "Mexico", modify
    label def co 2 "Guatemala", modify
    label def co 3 "El Salvador", modify
    label def co 4 "Honduras", modify
    label def co 5 "Nicaragua", modify
    label def co 6 "Costa Rica", modify
    label def co 7 "Panama", modify
    
    * Create the graph
    tabplot country years [iw=freq], bfcolor(%30) barwidth(1) subtitle("") ///
    showval(format(%9.0fc) mlabsize(vsmall)) xtitle("") xlabel(,labsize(small)) ///
    yasis ytitle("") ylabel(,labsize(small)) by(period)

    For a) I tried creating two separate tabplot graphs, omitting the y-axis from the second one, and joining them with -graph combine-, then played with fxsize() to equalize the individual panel widths. The problem there was that the ticks on the y-axis of the two panels were no longer aligned.


  • #2
    Just delete

    Code:
    by(period)
    and both problems will disappear. tabplot should please be cited as published via the Stata Journal.

    Comment


    • #3
      I discovered that to make graph combine keep the y-axes aligned I needed to use the option yscale(off). The following works well enough for dealing with a) above:

      Code:
      tabplot country years if period == 1 [iw=freq], bfcolor(%30) barwidth(1) ///
      subtitle("") showval(format(%9.0fc) mlabsize(vsmall)) xtitle("") ///
      xlabel(, labsize(small)) fxsize(79) yscale() yasis ytitle("") ///
      ylabel(,labsize(small)) name(g1, replace)
      
      tabplot country years if period == 2 [iw=freq], bfcolor(%30) barwidth(1) ///
      subtitle("") showval(format(%9.0fc) mlabsize(vsmall)) xtitle("") ///
      xlabel(, labsize(small)) fxsize(61) yscale(off) yasis ytitle("") ///
      ylabel(,labsize(small)) name(g2, replace)
      
      graph combine g1 g2
      Click image for larger version

Name:	gg.png
Views:	1
Size:	25.6 KB
ID:	1671971




      Last edited by Juan_Gonzalez; 03 Jul 2022, 15:09. Reason: Removed reference to issue b) in original request.

      Comment


      • #4
        Thank you Nick. I wanted to have two separate panels because of the gap in data collection in 2000-2005. tabplot is great either way, and indeed published via the Stata Journal -- my mistake.


        Comment


        • #5
          You could make your x-axis variable 1990, 1995, 2005, 2010, attach value labels and use the xasis option to get a gap.

          Comment


          • #6
            Great suggestion, thanks again! It does look better that way:

            Click image for larger version

Name:	Graph1.png
Views:	1
Size:	24.5 KB
ID:	1672037

            Comment

            Working...
            X