Announcement

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

  • Twoway scatter - labeling axis questions

    Hello,

    I have a couple questions re labeling axes in a twoway scatter plot. How can I:

    - Specify that x axis shows all values, when total number of values is unknown
    xlabel(1/15, valuelabel labsize(vsmall) angle(45)) ///

    - Specify that y axis shows intervals of 500, when max value is unknown
    ylabel(0(10)50, angle(0)) ylabel(0(500)2000, angle(0) axis(2)) ///

    The code that I am using is below. The intervals above are for `n'=1 but I want to be able to create graphs using the foreach loop that will label the categories properly for each of groups `n'=1 to `n'=6.

    foreach n of numlist 1/6 {
    preserve
    keep if ha==`n' & fy==17 & m_robson==.
    bysort ha fy m_robson (csrate): gen i_plot=_n
    labmask i_plot, values(name_short)
    codebook csrate_p numcase
    twoway (scatter csrate_p i_plot) ///
    (scatter numcase i_plot ///
    , yaxis(2) mcolor(gs10)) ///
    , ///
    title("CD rate by hospital, `ha`n''", justification(left) position(11)) ///
    subtitle("FY2017/18", justification(left) position(11)) ///
    ytitle("CD rate (%)", angle(0)) ///
    ytitle("Deliveries (n)", angle(0) axis(2)) ///
    yscale(range(0(10)50) titlegap(*5)) ///
    ylabel(0(10)50, angle(0)) ylabel(0(500)2000, angle(0) axis(2)) ///
    xtitle(Hospital) ///
    xlabel(1/15, valuelabel labsize(vsmall) angle(45)) ///
    xscale(titlegap(*5)) ///
    legend(position(11) col(3) region(lcolor(white)) symxsize(3) ///
    label(1 "CD rate %") label(2 "Deliveries (n)")) ///
    graphregion(fcolor(white) lcolor(black)) ///
    name(csrate_`ha`n''_hosp, replace) ///
    saving("$results/`ha`n''/Graphs/csrate_`ha`n''_hosp.gph", replace)
    graph export "$results/`ha`n''/Graphs/csrate_`ha`n''_hosp.pdf", replace
    restore
    }

    Thanks,

    David Puddicombe

  • #2
    You could probably get what you want using local macros. For example, right before the twoway command, calculate the max values for your x and y variables like this untested code:
    Code:
    summarize csrate_p
    local ymax `r(max)'
    summarize i_plot
    local xmax `r(max)'
    
    
    [other code omitted]
    
    
    ylabel(0(10)50, angle(0)) ylabel(0(500)`ymax', angle(0) axis(2)) ///
    xlabel(1/`xmax', valuelabel labsize(vsmall) angle(45)) ///
    If by "x axis shows all values" you mean all actual values of x in in the plot, try
    Code:
    levelsof i_plot, local(xlevs)
    
    
    [other code omitted]
    
    
    xlabel(`xlevs', valuelabel labsize(vsmall) angle(45)) ///
    David Radwin
    Senior Researcher, California Competes
    californiacompetes.org
    Pronouns: He/Him

    Comment


    • #3
      Hi David,

      Your first set of code was exactly what I am looking for. Thank you for your help.

      Best wishes,

      David Puddicombe

      Comment

      Working...
      X