Announcement

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

  • Creating twoway rcap with categorical data

    I am trying to graph the mean and min/max values that correspond to categorical data (names) as in the png file below. So far I have used the following code - a twoway rcap and scatter:

    twoway rcap max_daysPIF3 min_daysPIF3 RTA2 if TechTeam=="LECRDS", lcolor(yellow) yscale(range(0 800)) || ///
    scatter mean_daysPIF3 RTA2 if TechTeam=="LECRDS", mcolor(red) ///
    graphregion(fcolor(black)) plotr(fcolor(black) lcolor(black)) ///
    ylabel(, angle(horz)labsize(small) labcolor(white)) ///
    xlabel(1 "Anna Kaplina" 2 "Benjamin Larroquette" 3 "Claudia Ortiz" 4 "Gabor Vereczi" 5 "Henry Diouf" ///
    6 "Keti Chachibaia" 7 "Mame Diop" 8 "Pradeep Kurukulasuriya" 9 "Reis Lopez Rello" 10 "Stephen Gold" ///
    11 "Tom Twining-Ward" 12 "Yusuke Taishi", angle(45) labsize(vsmall) labcolor(white)) ///
    xtitle("RTA - LECRDS Team", size(small) margin (medium) color(white)) ///
    ytitle("Number of Days", size(small) margin (medium) color(white)) ///
    title("Mean Number of Days from PIF Submission to Approval", size(medium) color(white)) ///
    legend(pos(12) size(small) color(white) fcolor(black) lcolor(black) region(fcolor(black)) ///
    label(1 "Max/Min Days") label(2 "Mean Days"))

    I need the x label names (RTA2) to match the data and without any odd spaces in between.

    Also, a horizontal twoway graph would be ideal if possible.

    Click image for larger version

Name:	graph20_10Oct2014.png
Views:	3
Size:	92.4 KB
ID:	327505
    Attached Files

  • #2
    The most obvious problem here is that you are putting x axis labels at positions 1 to 12 on your x axis whereas the x axis variable evidently covers a different range and isn't even equally spaced. If you want equal spacing, then conversely you have to define a variable that takes on the values 1 to 12 and nothing in twoway does that for you. (This is a key difference from graph bar or graph dot and similar commands which have a built-in tendency to regard one axis as categorical.) If you

    Code:
    summarize RTA2, detail
    you should see that (and incidentally add to the information in your question).

    As you say, the graph would look much better rotated. Then you could have readable horizontal text labels on the vertical axis. That is all possible. rcap has a horizontal option.

    Some related technique is discussed in http://www.stata-journal.com/sjpdf.h...iclenum=gr0034

    Comment


    • #3
      Thank you for your help. I am still unclear - is it possible to create a twoway with one axis as categorical?
      I am aware rcap has a horizontal option, but scatter does not to my knowledge.

      Thus, I am leaning towards using a dot graph instead and just plotting min and max dots instead of rcap. Is it possible to connect the min/max dots with a line?

      However, I am unable to adjust the x-axis labels (RTA2) as the axis does not exist? Please advise.
      (i.e. I need graph Dot1 to be coloured as Dot2)

      graph dot (min) days_PIFsumb_appr (mean) days_PIFsumb_appr (max) days_PIFsumb_appr if TechTeam=="LECRDS", over (RTA2) ///
      marker(1, mcolor(blue)) marker(2, mcolor(red) msize(3)) marker(3, mcolor(yellow)) ///
      dots(mcolor(gray)) ///
      ylabel(, labsize(small) labcolor(white)) ///
      graphregion(fcolor(black)) plotr(fcolor(black) lcolor(black)) ///
      title("Number of Days from PIF Submission to Approval", size(medium) color(white)) ///
      legend(pos(12) row(1) size(small) color(white) fcolor(black) lcolor(black) region(fcolor(black)) ///
      label(1 "Min Days") label(2 "Mean Days") label(3 "Max Days"))

      Click image for larger version

Name:	Dot1.png
Views:	1
Size:	124.0 KB
ID:	335084 Click image for larger version

Name:	Dot2.png
Views:	2
Size:	73.0 KB
ID:	335083

      Comment


      • #4
        Originally posted by Judson Peck View Post
        Thank you for your help. I am still unclear - is it possible to create a twoway with one axis as categorical?
        I am aware rcap has a horizontal option, but scatter does not to my knowledge.
        twoway scatter has an horizontal option in the sense that you can just reverse the order of the variables, so instead of typing twoway scatter y xyou type twoway scatter x y.
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment


        • #5
          General remarks

          You are in confusing territory, where changing the design slightly means using quite different graph commands. I can well imagine that the designers of graph put a lot of time and effort into trying to avoid this problem, the result of other decisions, but this outcome was the downside of a decision with more upsides.


          Categorical axes

          The term "categorical axis" is ambiguous. Stata has a very specific sense of what it means by "categorical axis", and uses that term in documentation of commands such as graph bar.

          Code:
          search categorical axis
          leads to examples.

          In contrast absolutely nothing stops you using defining one or even both axes of a twoway graph to show what you think as categories. Stata does nothing differently as, naturally, it has no idea about how you regard your variables here, as the syntax is the same for something measured, something counted, and something given arbitrary numerical codes. There is no discussion of "categorical axis" under twoway because there is nothing to discuss.


          horizontal options and which axis is y

          The function of the horizontal option in twoway rcap is to flag that capped bars are drawn horizontally, not vertically. scatter does not need a horizontal option because all you need to do is to exchange the variables. Conversely, changing the order of the variables supplied to rcap would define the same interval.

          With graph dot your horizontal axis is called the y axis, regardless of convention elsewhere. The syntax diagram for graph dot spells out that the variables plotted on that axis are regarded as yvars

          Code:
          graph dot  yvars [if] [in] [weight] [, options]
          See also the first paragraph of the Description section in the help for graph dot, where this point is hammered home.


          Showing intervals

          If you want to connect points with line segments, you have to use twoway rcap or twoway spike. You can't do that with graph dot.

          Comment


          • #6
            Please forgive my lack of technical terminology and STATA experience, but I believe you understand what I am asking:

            1. Is it possible to format the x-axis of a dot graph? (i.e. change the label colour/size?) STATA says x-axis does not exist...? You can see the problem in the black dot graph above.

            2. You say "nothing stops you using defining one or even both axes of a twoway graph to show what you think as categories," so how is this achieved?

            Thank you for your continued help.

            Comment


            • #7
              #1 Sorry, but I don't know which graph you're referring to and precisely which problem you want fixed.

              #2 is just the approach you've used yourself in (e.g.) post 1 and which is discussed in many places (e.g. the paper cited in post 2).

              Please look at the FAQ Advice. Section 12 requests

              If you can, reproduce the error with one of Stata's provided datasets, a small fragment of your dataset, or a simple concocted dataset that you include in your posting.

              Section 18 is also instructive.

              Comment


              • #8
                #1 I have re-attached the graph below. The labels along the vertical axis exist but do not appear because I cannot figure out how to change the color. I get the following error
                -xlabels(, labcolor(white)) not allowed, xaxis1 does not exist-

                Click image for larger version

Name:	Dot2.png
Views:	2
Size:	73.0 KB
ID:	362598

                Comment


                • #9
                  Blacking out all background so that your categorical axis labels disappear counts as self-inflicted injury! You want something like

                  Code:
                  ... over(RTA2, label(labcolor(white)))
                  You have a generic clue in the help for graph dot that the vertical axis is categorical and a specific clue that there are cat_axis_label_options documented one click away.

                  Comment


                  • #10
                    Thank you!

                    Comment

                    Working...
                    X