Announcement

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

  • Change font size on x-axis

    I'm having a frustrating time automating a change in font for the x-axis using the package profileplot which lets you make a time series graph of a wide dataset.

    https://stats.idre.ucla.edu/stata/fa...data-in-stata/

    The following code does not allow option labsize on xlabel.
    profileplot TX_12 TX_14 TX_16 TX_18 if REGION==1, title(Transplant #) xl(1 "12" 2 "14" 3 "16" 4 "18", labsize(vsmall)) xtitle(Year,size(vsmall)) /*
    */ ytitle(Count , size(vsmall)) yl(0 50 100 150 200, labsize(vsmall)) yscale(range(0 200)) legend(size(vsmall)) by(PROGRAM)

    However, this code works fine specifying only the ylabel.
    profileplot TX_12 TX_14 TX_16 TX_18 if REGION==1, title(Transplant #) xl(1 "12" 2 "14" 3 "16" 4 "18") xtitle(Year,size(vsmall)) /*
    */ ytitle(Count , size(vsmall)) yl(0 50 100 150 200, labsize(vsmall)) yscale(range(0 200)) legend(size(vsmall)) by(PROGRAM)

    Any ideas why I cannot specify an option for the xlabel? Is it because I'm replacing values on the x-axis with text?

  • #2
    We can't see your data because you don't give a data example and we can't see your graph either. Please see https://www.statalist.org/forums/help#stata (and while you are visiting please note our preference for full real names at https://www.statalist.org/forums/help#realnames).

    But the problem is clear and the code of profileplot is visible to inspect. In essence, xlabel() there is non-standard such that extra suboptions aren't handled correctly. This data example from the page you cite is here followed by a call to a ugly hack of profileplot with an extra option to take x-axis label suboptions.

    Code:
    clear 
    input id time1 time2 time3 time4 
     1 23 25 25 30 
     2 14 17 20 23 
     3 32 33 34 24 
     4 33 35 42 50 
     5 5 17 22 22 
    end 
    set scheme s1color 
    profileplot time1 time2 time3 time4, by(id)
    
    profileplot2 time?, by(id) xlabelopts(labsize(vsmall))
    Here is the code for profileplot2.ado.


    Code:
    *! hack NJC 26mar2019 
    *! version 1.2 -- 22nov11, 19may08, 2nov07, 31oct07 -- pbe
    program define profileplot2
    version 8.2
    syntax varlist [if] [in] [pweight], by(varname) [ MEDian XLabel(string) ///
            XTitle(string) MSYMbol(string) ANGle(integer 0) LEGend(string)  ///
            Xlabelopts(str asis) *]
    
     preserve
     
     if "`if'"~="" | "`in'"~="" {
       keep `if' `in'
     }
     local pvar = substr("`exp'",3,.)
     keep `varlist' `pvar' `by' 
     
     local type "mean"
     if "`median'"~="" {
       local type "median"
     }
     
     local kvars : word count `varlist'  /* get number of variables */
     local q=char(34)
     local label ""
     local i=0
     foreach V of varlist `varlist' {
       local i=`i' + 1
       local label = `"`label'"' + " " + `"`i'"' + " " + `"`q'"' + "`V'" + `"`q'"'
       rename `V' value`i'
     }
     
     /* restructure data prior to plotting */
     collapse (`type') value* [`weight' `exp'], by(`by')
     quietly reshape long value, i(`by') j(Variables)
    
     local htitle ""
     if "`xtitle'"~="" {
        local htitle "ttitle(`xtitle')"
     }
     if "`xlabel'"~="" {
       local label=`"`xlabel'"'
     }
     label def var `label'
     label values Variables var
     label var value "`type'"
     if "`msymbol'"=="" {
       local msymbol "O"
     }
    
     * use xtline to draw profiles
     quietly xtset `by' Variables
     xtline value, overlay tlabel(#`kvars', valuelabels) /// 
            addplot(scatter value Variables, msymbol("`msymbol'") ///
            legend(`legend') ) ///
            `htitle' `options'  xlabel(,angle(`angle') `xlabelopts')
    end
    Note that parplot (SSC) offers some related functionality.

    Comment


    • #3
      Thanks so much! That provided an alternative option to handle xlabel.

      Comment

      Working...
      X