Announcement

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

  • Restricting y-axis of spineplots

    I am trying to create a series of spineplots. Spineplots (user-written, ssc spineplot) show categories as fractions of a total and by default, the range of the y-axis is set to 0 to 1.
    My variable rut_cat2 has three categories but I am only interested in showing two of those (and I set the color of the last category to white). Since their fraction is relatively small, I want to restrict the range of the y-axis to show 0 to 0.2. Is there any way to do this?

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(sex_couple_age rut_cat2)
    2 3
    2 2
    4 3  
    4 1
    4 3  
    5 2
    2 1  
    3 3
    1 3  
    3 2
    1 2  
    4 3  
    5 3  
    3 3  
    4 1  
    1 3
    4 2
    1 3  
    3 1
    4 3
    end
    label values sex_couple_age sex_couple_age
    label def sex_couple_age 1 "Single men", modify
    label def sex_couple_age 2 "Partnered men", modify
    label def sex_couple_age 3 "Single women", modify
    label def sex_couple_age 4 "Partnered women", modify
    label def sex_couple_age 5 "Elderly single men", modify
    label def sex_couple_age 6 "Elderly partnered men", modify
    label def sex_couple_age 7 "Elderly single women", modify
    label def sex_couple_age 8 "Elderly partnered women", modify
    label values rut_cat2 rut_cat2
    label def rut_cat2 3 "Non-user", modify
    
    spineplot rut_cat2 sex_couple_age, bar3(color("110 142 132")) bar2(color("192 220 192")) bar1(color(white)) barall(blwidth(tiny) blcolor(white)) ///
    ylabel(none, noticks axis(1)) ///
    xlabel(none, noticks axis(1))  xlabel(, angle(45) axis(2)) ///
    xtitle("") xtitle("", axis(2)) ytitle("", axis(2)) legend(off) plotregion(margin(zero)) graphregion(margin(vsmall) c(white)) xsize(4)
    Attached Files
    Last edited by Annika Elwert; 22 May 2024, 03:15.

  • #2
    spineplot is from the Stata Journal. It doesn't offer this option.

    If you want to suppress one category, I would calculate what you want to show and only then call up twoway or some wrapper for twoway to plot it. This example is just indicative and uses tabplot from the Stata Journal.


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(sex_couple_age rut_cat2)
    2 3 
    2 2 
    4 3  
    4 1 
    4 3  
    5 2 
    2 1   
    3 3 
    1 3  
    3 2 
    1 2  
    4 3  
    5 3  
    3 3  
    4 1  
    1 3 
    4 2 
    1 3  
    3 1 
    4 3 
    end
    label values sex_couple_age sex_couple_age
    label def sex_couple_age 1 "Single men", modify
    label def sex_couple_age 2 "Partnered men", modify
    label def sex_couple_age 3 "Single women", modify
    label def sex_couple_age 4 "Partnered women", modify
    label def sex_couple_age 5 "Elderly single men", modify
    label def sex_couple_age 6 "Elderly partnered men", modify
    label def sex_couple_age 7 "Elderly single women", modify
    label def sex_couple_age 8 "Elderly partnered women", modify
    label values rut_cat2 rut_cat2
    label def rut_cat2 3 "Non-user" 1 "something" 2 "delicate", modify
    label var rut_cat2 "better text needed here"
    
    bysort sex_couple_age rut_cat2: gen numer = _N 
    bysort sex_couple_age : gen denom = _N 
    gen toshow = strofreal(numer) + " (" + strofreal(100 * numer/denom, "%2.1f") + "%)"
    
    tabplot sex_couple_age rut_cat2 if rut_cat2 < 3, showval(toshow) subtitle("") ytitle("") separate(rut_cat2)

    Comment


    • #3
      Thanks a lot, Nick! I will look into tabplots.

      Comment

      Working...
      X