Announcement

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

  • Issue with Graph Title Position - Issue with Ring position

    Hello:

    I'm trying to move a graph title to outside the plot area, specifically above it. I increase the ring position number, but it does not change the position. Here's the code that I'm using:

    graph bar (asis) Republicans Democrats All, graphregion(margin(t+5 b+5)) /// yline (54, lcolor(gray)) ///
    scheme(s1color) ///
    ylabel(, labsize(small)) ///
    ytitle("Percent that agree", size(medium)) ///
    title("Should U.S. put its interests first when dealing with allies?", position (11) ring(3)) ///
    blabel(total, size(medium)) ///
    bar(1, color(red)) bar(2, color(blue)) bar(3, color(gray)) ///
    bargap(50) ///
    legend(off) ///
    showyvars

    I feel like I must be missing something obvious here. Any help would be greatly appreciated!

    Best, Gene

  • #2
    If you look at what the help on the positioning of titles says:
    Code:
    Now consider two titles -- say title() and subtitle() -- both located at position(12).  Which is to appear first?
    That is determined by their respective ring() values.  ring() specifies ordinally how far a title is from the plot region.  
    The title with the larger ring() value is placed farther out.
    So the number really makes no difference, unless it changes the rank of different text boxes. Consider:

    Code:
    sysuse nlsw88, clear
    
    graph bar hours, over(grade) name(bar1, replace) title("My First Graph", ring(300)) subtitle("An example", ring(2)) scheme(s2color)
    This produces:
    Click image for larger version

Name:	Screenshot 2022-09-15 at 6.15.52 AM.png
Views:	1
Size:	152.3 KB
ID:	1681999




    Now consider this code:
    Code:
    graph bar hours, over(grade) name(bar2, replace) title("My Second Graph", ring(3)) subtitle("An example", ring(400)) scheme(s2color)
    which produces:
    Click image for larger version

Name:	Screenshot 2022-09-15 at 6.16.08 AM.png
Views:	1
Size:	157.7 KB
ID:	1682000




    To get what you need, you want to use the margin suboption for title. Consider this, which changes the code from the first example only by adding the margin suboption:

    Code:
    graph bar hours, over(grade) name(bar3, replace) title("My Third Graph", ring(300) margin(0 0 40 0)) subtitle("An example", ring(2)) scheme(s2color)
    This produces the following graph:
    Click image for larger version

Name:	Screenshot 2022-09-15 at 6.16.21 AM.png
Views:	1
Size:	135.3 KB
ID:	1682001

    Last edited by Hemanshu Kumar; 14 Sep 2022, 18:53.

    Comment


    • #3
      Hemanshu: Thank you for the detailed explanation with examples. This really helped. My problem has been solved.

      Comment

      Working...
      X