Announcement

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

  • graph combine / grc1leg question: How to get one axis title for alle subgraphs?

    Hello everybody,

    I have a queation about graph combine, or in my specific case grc1leg, but since the latter is a wrapper of the former the solution should fit to both commands.
    If this has been answered many times before I apologize, but I didn't find related posts on the forum.

    Here's my problem: After combining the graphs I would like only one xtitle for both graphs (so I dont have the same xtitle below each subgraph).
    I tried using a b1-title in the grc1leg, but then the title is displayed below the legend, which looks odd.
    Does anyone know how to get the title above the legend?

    Actually, I'd like to replicate the outcome of using the by()-option of twoway.

    Heres a code example:
    Code:
    sysuse auto, clear
    
    * Desired outcome using by-option:
    twoway (scatter price headroom, by(foreign, graphregion(color(white)))) ///
           (qfit price headroom), ///
           ytitle("Price")
            
    * My try on it:
    global graphnames
    forv i=0/1 {
        twoway (scatter price headroom if foreign==`i') ///
               (qfit price headroom if foreign==`i'), ///
        title("Foreign=`i'") ///
        xtitle("") ytitle("") ///
        graphregion(color(white)) ///
        name(gr_`i', replace) nodraw
        
        global graphnames $graphnames gr_`i'    
    }
    grc1leg $graphnames, ycommon xcommon graphregion(color(white)) rows(1) b2title("Headroom") l1title("Price")
    
    // ... they are not identical...
    Here's the output of the by-option:
    Click image for larger version

Name:	byoption.png
Views:	1
Size:	27.3 KB
ID:	1527269

    And that's what I get when trying to replicate it by using grc1leg:
    Click image for larger version

Name:	grc1leg.png
Views:	1
Size:	27.0 KB
ID:	1527270




  • #2

    gr1cleg is by Vince Wiggins and can be installed from
    Code:
    net install gr1cleg
    Although not explicit, the option -ring()- specifies where the legend is placed. The default is ring(0) which implies the plot region. You want to specify ring>0 for outside the plot region. For your case,
    Code:
    grc1leg $graphnames, ycommon xcommon graphregion(color(white)) rows(1) b2title("Headroom") l1title("Price") ring(2)
    does it.

    Comment


    • #3
      Thank you very much, this solved the problem!
      And of course also thank you referring to Vince Wiggins contribution - it's one extremely useful command.

      Comment

      Working...
      X