Announcement

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

  • twoway plots: Center title in based on graph region, not plot region?

    Hello everybody,

    I have a plot where I extend the margin around the plot region in order to display marker labels as a substitute for the legend.
    When I do this, the plot title is still centered with respect to the plot region, but I would like to have it centered with respect to the entire graph region.
    Any ideas how to do this?

    Using the pos() options inside title() did not help.

    Thanks!
    Boris

    Here is some example code:
    Code:
    clear
    input num time var
    1    1    1
    1    2    2
    1    3    3
    1    4    5
    1    5    2
    2    1    7
    2    2    4
    2    3    2
    2    4    5
    2    5    9
    end
    
    gen name = "Louis George Maurice" if num==1
    replace name = "Roseanne Marie Audile" if num==2
    
    * Title centered wrt plot-region, not graph region:
    #delimit ;
    twoway (connect var time if num==1, col(navy))
           (scatter var time if time==5 & num==1, msym(none) mlab(name) mlabcol(navy))
           (connect var time if num==2, col(maroon))
           (scatter var time if time==5 & num==2, msym(none) mlab(name) mlabcol(maroon))
           ,
           title("Not centered on graph region")
           graphregion(color(white) margin(3 30 1 3))
           legend(off)
           name(take1,replace)
           ;
    #delimit cr

  • #2
    The -span- suboption seems to be what you're looking for. Just add

    Code:
    , span
    to your title option.

    Comment


    • #3
      Hi Ali,
      thank you for your reply. But this does not seem to solve the problem.
      I added some expample code with the span option inside title(), but it still seems to center the title in the plot region rather than the graph region.


      Code:
      clear
      input num time var
      1    1    1
      1    2    2
      1    3    3
      1    4    5
      1    5    2
      2    1    7
      2    2    4
      2    3    2
      2    4    5
      2    5    9
      end
      
      gen name = "Louis George Maurice" if num==1
      replace name = "Roseanne Marie Audile" if num==2
      
      * Title centered wrt plot-region, not graph region:
      #delimit ;
      twoway (connect var time if num==1, col(navy))
             (scatter var time if time==5 & num==1, msym(none) mlab(name) mlabcol(navy))
             (connect var time if num==2, col(maroon))
             (scatter var time if time==5 & num==2, msym(none) mlab(name) mlabcol(maroon))
             ,
             title("Not centered")
             graphregion(color(white) margin(3 50 1 3))
             legend(off)
             name(take1,replace)
             ;
      #delimit cr
      
      
      * Title centered wrt plot-region, not graph region:
      #delimit ;
      twoway (connect var time if num==1, col(navy))
             (scatter var time if time==5 & num==1, msym(none) mlab(name) mlabcol(navy))
             (connect var time if num==2, col(maroon))
             (scatter var time if time==5 & num==2, msym(none) mlab(name) mlabcol(maroon))
             ,
             title("Not centered (w span option)", span)
             graphregion(color(white) margin(3 50 1 3))
             legend(off)
             name(take2,replace)
             ;
      #delimit cr

      Comment


      • #4
        What about using "brute force"

        Code:
        #delimit ;
        twoway (connect var time if num==1, col(navy))
               (scatter var time if time==5 & num==1, msym(none) mlab(name) mlabcol(navy))
               (connect var time if num==2, col(maroon))
               (scatter var time if time==5 & num==2, msym(none) mlab(name) mlabcol(maroon)) ,
               graphregion(color(white) margin(3 50 1 3))
               legend(off)
               name(take2,replace)    ;
        #delimit cr
        graph combine take2, name(take3, replace) title("Centered")

        Comment


        • #5
          Alright, fair enough. Thank you!

          Comment

          Working...
          X