Announcement

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

  • Vertical and left justified added text to graph

    Hi fellow Stata users!

    I'm making up a graph and would like some added text labels to be added that are vertically oriented and left justified (so they look like they're all "standing up" with even bottoms).

    I'm not sure why this isn't working:

    Code:
    clear 
    graph drop _all
    set obs  1
    
    local location_u1 -1
    local location_1 -0.75
    local location_u2 -0.5
    local location_2 -0.25
    local location_u3 0
    local location_3 0.25
    local location_u4 0.5
    local location_4 0.75
    local location_u5 1
    
    gen location_u1 = `location_u1'
    gen location_1 = `location_1'
    gen location_u2 = `location_u2'
    gen location_2 = `location_2'
    gen location_u3 = `location_u3'
    gen location_3 = `location_3'
    gen location_u4 = `location_u4'
    gen location_4 = `location_4'
    gen location_u5 = `location_u5'
    
    
    twoway scatter location_u1 location_u1 , msym(i) ///
        || scatter location_u5 location_u5 , msym(i) ///
            text(`location_u3' `location_1' "p <= 0.01", orientation(vertical) justification(left)) ///
            text(`location_u3' `location_2' "0.01 <= p < 0.05", orientation(vertical) justification(left)) ///
            text(`location_u3' `location_3' "0.05 <= p < 0.1", orientation(vertical) justification(left)) ///
            text(`location_u3' `location_4' "p > 0.1", orientation(vertical) justification(left)) ///
        legend(off) graphregion(col(white)) ///
        xlabel(`location_u1' `location_u5', notick nogrid labcolor(white)) xscale(alt lcolor(white)) ///
        ylabel(`location_u1' `location_u5', notick nogrid labcolor(white)) xscale(alt lcolor(white))
    Thanks for any help!
    Cheers,
    Simon.

  • #2
    Your code works, i.e. is legal, although I wonder whether you really want vertical orientation.


    This may indicate some useful and simpler technique. Note e.g. that <= can be improved on.

    Code:
    clear 
    graph drop _all
    set obs  1
    
    local location_u1 -1
    local location_1 -0.75
    local location_u2 -0.5
    local location_2 -0.25
    local location_u3 0
    local location_3 0.25
    local location_u4 0.5
    local location_4 0.75
    local location_u5 1
    
    
    twoway scatteri `location_u3' `location_1' (9) "p {&le} 0.01"           ///
        || scatteri `location_u3' `location_2' (9) "0.01 {&le} p < 0.05" ///
        || scatteri `location_u3' `location_3' (9) "0.05 {&le} p < 0.1"  ///
        || scatteri `location_u3' `location_4' (9) "p > 0.1"             ///
        , legend(off) scheme(s1color)

    Comment


    • #3
      Thanks Nick, the symbol addition is excellent! Unfortunately, as this is just one component of a more complex system I've been asked to create, I do need the vertical orientation. I seem to be able to get the vertical orientation without the justification or the justification without the vertical orientation!

      I'm after the text to begin at the point and continue upwards so that they're all lined up at the bottom, in a way analogous to the text coming from axis labels.

      I've made it work by just forcing the width of the textbox to be larger using width(#) and that seems to do the trick (though perhaps a little messy and required some trial and error to get the text box size just right, actually I can make it super small, like width(0.01) and it works).

      Cheers,
      Simon.
      Last edited by Simon Turner; 26 Aug 2019, 17:06.

      Comment


      • #4
        Originally posted by Simon Turner View Post
        Thanks Nick, the symbol addition is excellent! Unfortunately, as this is just one component of a more complex system I've been asked to create, I do need the vertical orientation. I seem to be able to get the vertical orientation without the justification or the justification without the vertical orientation!

        I'm after the text to begin at the point and continue upwards so that they're all lined up at the bottom, in a way analogous to the text coming from axis labels.

        I've made it work by just forcing the width of the textbox to be larger using width(#) and that seems to do the trick (though perhaps a little messy and required some trial and error to get the text box size just right, actually I can make it super small, like width(0.01) and it works).

        Cheers,
        Simon.
        I should add the code, sorry....

        Code:
        clear
        graph drop _all
        set obs  1
        
        local location_u1 -1
        local location_1 -0.75
        local location_u2 -0.5
        local location_2 -0.25
        local location_u3 0
        local location_3 0.25
        local location_u4 0.5
        local location_4 0.75
        local location_u5 1
        
        gen location_u1 = `location_u1'
        gen location_1 = `location_1'
        gen location_u2 = `location_u2'
        gen location_2 = `location_2'
        gen location_u3 = `location_u3'
        gen location_3 = `location_3'
        gen location_u4 = `location_u4'
        gen location_4 = `location_4'
        gen location_u5 = `location_u5'
        
        twoway scatter location_u1 location_u1 , msym(i) ///
            || scatter location_u5 location_u5 , msym(i) ///
                text(`location_u3' `location_1' "p {&le} 0.01", orientation(vertical) justification(left) width(0.01)) ///
                text(`location_u3' `location_2' "0.01 {&le} p < 0.05", orientation(vertical) justification(left) width(0.01)) ///
                text(`location_u3' `location_3' "0.05 {&le} p < 0.1", orientation(vertical) justification(left) width(0.01)) ///
                text(`location_u3' `location_4' "p > 0.1", orientation(vertical) justification(left) width(0.01)) ///
            legend(off) graphregion(col(white)) ///
            xlabel(`location_u1' `location_u5', notick nogrid labcolor(white)) xscale(alt lcolor(white)) ///
            ylabel(`location_u1' `location_u5', notick nogrid labcolor(white)) xscale(alt lcolor(white))

        Comment

        Working...
        X