Announcement

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

  • Overlaying a line graph over a catplot or tabplot graph

    Dear Statalisters,

    First time statalist user here. I am studying the supply and demand of fishing poles in warehouses by quarter and I am trying to replicate the graph below made in Excel: Basically, a stacked bar graph showing the percentages of the fishing pole availability categories overlaid with a line graph of the total number of customers buying the poles every quarter.
    Click image for larger version

Name:	Excel.png
Views:	1
Size:	18.3 KB
ID:	1533366


    The main problem is that I cannot figure out how to do the overlaying of the two graph types in stata either using catplot or tabplot. Would anyone have encountered a similar problem and would have any advice to offer? is it actually possible to do the overlay? I've been stuck on this for days and any help would be appreciated.

    I produced the catplot with the code below.

    Code:
    catplot method_available quarter [aw=normwt] if ma==1,  ///
    percent (quarter) recast (bar)  blabel(bar, position(center) format(%3.1f) size(2)) ///
    var1opts(label(labsize(small))) ///
    var2opts(label(labsize(small)) relabel(`r(relabel)')) ///
    ytitle("Percent of facilities offering FP", size(small)) ///
    title("Public" ///
    , span size(medium)) ///
    intensity(25) ///
    asyvars stack ///
    bar(1, color(blue) fintensity(inten80)) ///
    bar(2, color(blue) fintensity(inten60)) ///
    bar(3, color(red) fintensity(inten90)) ///
    bar(4, color(orange) fintensity(inten60)) ///
    bar(5, color(navy) fintensity(inten80)) ///
    legend(off) name(public, replace)
    
    catplot method_available quarter [aw=normwt] if ma==2,  ///
    percent (quarter) recast (bar)  blabel(bar, position(center) format(%3.1f) size(2)) ///
    var1opts(label(labsize(small))) ///
    var2opts(label(labsize(small)) relabel(`r(relabel)')) ///
    ytitle("Percent of facilities offering FP", size(small)) ///
    title("Private" ///
    , span size(medium)) ///
    intensity(25) ///
    asyvars stack ///
    yscale (off) ///
    bar(1, color(blue) fintensity(inten80)) ///
    bar(2, color(blue) fintensity(inten60)) ///
    bar(3, color(red) fintensity(inten90)) ///
    bar(4, color(orange) fintensity(inten60)) ///
    bar(5, color(navy) fintensity(inten80)) ///
    legend(rows(1) stack size(small) ///
    order(1 "Does not" "Provide method" 2 "Currently in stock and" "no stock out last 3 months" 3 "Provides method" "and confirmed in stock" ///
    4 "Provides method but" "out of stock at visit") ///
    symplacement(center) ///
    title(Method provision categories, size(small))) name(private, replace)
    
    grc1leg public private
    Click image for larger version

Name:	catplot.png
Views:	1
Size:	51.0 KB
ID:	1533363




    The tabplot was produced using the code below.
    Code:
    ****TABPLOT
    local spaces = 3 * uchar(9)
    tabplot method_available quarter, by(ma, compact note("% by method and quarter", size(small))) ///
        percent(method_available quarter) showval(offset(0.2))   ///
        graphregion(color(white))  ytitle("") xtitle("`spaces'Quarter", size(small))  ///
         xsc(titlegap(*8)) subtitle(, fcolor(none))  ///
        separate(method_available) barall(blcolor(black)) bar1(bfcolor(orange)) bar2(bfcolor(blue)) bar3(bfcolor(purple)) bar4(bfcolor(red))
    Click image for larger version

Name:	tabplot.png
Views:	1
Size:	28.1 KB
ID:	1533364

    Attached Files
    Last edited by Peter Amadou; 24 Jan 2020, 00:50.

  • #2
    Hi Peter,
    I have been having the same problem and still haven't found any solution.
    So far I know that Catplotlib is not compatible with twoway or with addplot

    Please let me know if you figured it out!

    Thanks.

    Comment


    • #3
      I missed the first post in this thread at the time.

      catplot is from SSC and based on graph hbar or graph bar. It's not compatible with graph twoway.

      tabplot is from the Stata Journal and based on graph twoway.

      I have no idea what catplotlib is, unless a subconscious averaging of catplot and Python's matplotlib.

      For a combined stacked bar and line plot, you shouldn't start from either. You need a hybrid of twoway rbar and twoway line, but detailed code would be premature without a data example.

      Comment

      Working...
      X