Announcement

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

  • Changing category label formatting using catplot

    Hi all,

    I am using --catplot-- with Stata 14.1. The dataex output to create sample data is at the bottom of this post.

    I am trying to produce a simple graph of the percent of respondents on a survey who gave different responses to a multiple choice question. My code is below, and the graph it produces follows (note that the color is set by a scheme provided by my job).

    Code:
    mylabels 0(20)100, myscale(@) local(pctlabel) suffix("%")
    splitvallabels q6, length(5) nobreak recode
    catplot q6, missing allcategories recast(bar) percent /// 
                xsize(3) ysize(2.2) scale(1) ytitle("Percent") /// 
                ylabel(`pctlabel') b1title("") yvaroptions(relabel(`r(relabel)') label(labsize(vsmall))) outergap(*3.5) ///
        saving("$data\5_Analysis\6_q6.gph", replace)
    Click image for larger version

Name:	6_q6.png
Views:	1
Size:	21.6 KB
ID:	1353981



    I have two questions:
    (1) I would like to reduce the font size of the labels on the x-axis, as well as make the text fall on multiple lines, so that they no longer overlap. I have successfully done this using the "yvaroptions" option in the --graph bar-- command previously (hence I included it in my code), but when using it here with catplot, it seems to have no impact on the appearance of these labels. Is there a way to do this with catplot? I can change the scale but wondered if it was possible to affect these more directly.
    (2) As you'll note in the data, there are response options (eg "Local government resources") which none of the survey respondents selected, so they are not showing up in the graph. I would like to still have these categories show up, as zero % (ie, a space on the graph), so that viewers know that that response was an option but no one picked it. I thought the "allcategories" option would do this, but it seems to have had no impact. Is there a way to do this?



    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str17 v1 byte q6
    "R_2"  6
    "R_3" .r
    "R_4"  1
    "R_5"  1
    "R_6"  2
    "R_1"  1
    end
    label values q6 labq6
    label def labq6 1 "State resources", modify
    label def labq6 2 "Federal resources", modify
    label def labq6 3 "Local government resources", modify
    label def labq6 5 "Fees from service providers", modify
    label def labq6 6 "Mixed sources", modify
    label def labq6 .r "Respondent missing", modify
    label var v1 "ResponseID" 
    label var q6 "How is your infant mortality organizing/planning group funded"

    Thank you all very much in advance for your help.

    Julia

  • #2
    catplot, mylabels and splitvallabels are all from SSC. See FAQ Advice #12 asking that you specify the provenance of user-written programs discussed.

    The graph scheme used and where you save graphs are not reproducible by us but not material to the problem. But your problem can be reproduced without knowing either.

    You have more problems with this design than stated. What's happened to the variable label?

    Once people try to make labels very small, I am convinced that they are going in the wrong direction. Which category is which is a major part of the information here and should be very easy to read off.

    Here's my suggestion:

    Code:
    clear
    set scheme s1color 
    input str17 v1 byte q6
    "R_2"  6
    "R_3" .r
    "R_4"  1
    "R_5"  1
    "R_6"  2
    "R_1"  1
    end
    label values q6 labq6
    label def labq6 1 "State resources", modify
    label def labq6 2 "Federal resources", modify
    label def labq6 3 "Local government resources", modify
    label def labq6 5 "Fees from service providers", modify
    label def labq6 6 "Mixed sources", modify
    label def labq6 .r "Respondent missing", modify
    label var v1 "ResponseID" 
    label var q6 "How is your infant mortality organizing/planning group funded?"
    
    foreach p in catplot mylabels { 
        capture ssc inst `p'
    }
    
    mylabels 0(20)100, myscale(@) local(pctlabel) suffix("%")
    
    catplot q6, missing percent /// 
                ytitle("Percent") /// 
                ylabel(`pctlabel') l1title(, pos(12))
    Click image for larger version

Name:	anotherbarplot.png
Views:	1
Size:	14.7 KB
ID:	1353990


    There's no reason to split the value labels with horizontal bars. We should move the position of the variable label to make it more readable. (Perhaps I should insert some extra intelligence into catplot to automate that.)

    If you really prefer vertical bars, I would consider angling the labels rather than trying to make them very small.

    Your numbered questions are not yet answered.

    (1) How to make the value labels very small with catplot? Consider the effects of this:

    Code:
    sysuse auto
    catplot foreign, recast(bar) var1opts(label(labsize(vsmall)))
    (2) How to show categories not represented in the data? I don't know an easy way to do this other than to rewrite the problem using twoway bar.

    Comment


    • #3
      Dear Nick,

      Thank you very much for the response.

      The variable label I purposefully suppressed with the "b1title("")" part of my code, since this is all going in to a powerpoint where the questions are included in the titles of the slides. But that is also irrelevant to my original questions.

      Using var1opts solves my first question perfectly - to be clear, I don't necessarily need the font to be vsmall, and I agree with your point on readability. I was simply looking for a way of adjusting the font to whatever I needed it to be to promote readability.

      I guess I'll just have to either add a note to list out the question categories that no one selected, or experiment with twoway bar.

      Thanks again,
      Julia


      Comment

      Working...
      X