Announcement

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

  • Legend position in a twoway connected by group graph

    Hi Statalist,

    I am writing to you because I am having some problems in the process of making a graph, particularly in defining the location of the legend with the labels.
    It is a twoway connected graph, which includes the labor force participation for eight age groups, differentiated for men and women.

    I've tried the following definition, but the box still fills the chart space instead of being below the chart area (I get a huge box with the legend in the left and the graph is cramped on the right side).
    How can I have the legend box below the graph area, with two rows and four columns with the label of the eight age groups?

    Code:
    preserve
    collapse d_lab_force, by(sex cohort age_group)
    replace d_lab_force = d_lab_force * 100
    separate d_lab_force, by(cohort)
    
    * Graph.
    #delimit;
    graph twoway (connected d_lab_force1 d_lab_force2 d_lab_force3 d_lab_force4 ///
        d_lab_force5 d_lab_force6 d_lab_force7 d_lab_force6 age_group), by(sex, note("")) graphregion(color(gs15))
        legend(label(1 "1916-1925") label(2 "1926-1930") label(3 "1931-1935") ///
        label(4 "1936-1940") label(5 "1941-1945") label(6 "1946-1950") ///
        label(7 "1951-1955") label(8 "1956-1960") ///
        subtitle("Birth year", size(small)) size(small))
        ylabel( 0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", ///
            labsize(small) angle(horizontal)) title("")
        xlabel(1 "35-39" 2 "40-44" 3 "45-49" 4 "50-54" 5 "55-59" 6 "60-64" ///
            7 "65-69" 8 "70-74", angle(0) labsize(small))
        ytitle("Proportion in the labor force", size(small))
        xtitle("Age", size(small))
        ;
    #delimit cr
    restore


    Do any of you know how to do this?
    I am currently using Stata 17.

    Thanks in advance,
    Isidora.

  • #2
    Dear Isidora,

    try if specifying the legend like this works:
    legend(order(1 "1916-1925" 2 "1926-1930" 3 *insert the rest here*) position(6) rows(2) cols(4))

    Comment

    Working...
    X