Announcement

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

  • Code for formatting axes in graphs

    Hello,

    I have a neat little graph showing each day for each participant in my study. I have created this graph using the following code (you can run using dataex data below). I am having trouble doing something simple: limiting the x axis to 180, and including tick marks on the x axis for every 10 days. I can easily do this in the graph editor by setting the range from 0 to 180 and the delta to 10 but can't figure out how to add this in the code. I tried (as you can see below) to include the code xsc(range(0 180)) but the x axis is still showing 0-200. Hopefully I'm just missing something small?

    Thank you!

    Sarah




    twoway (rbar idreset low2 day if type==0, color(blue)) ///
    (rbar idreset low2 day if type==1, color(green)) ///
    (rbar idreset low2 day if (type==2|type==7), color(purple)) ///
    (rbar idreset low2 day if type==3, color(black)) ///
    (rbar idreset low2 day if (type==6|type==4), color(yellow)) ///
    ,xsc(range(0 180)) legend(order(1 "No weight transmission" 2 "Weight transmission" 3 "Hospitalized" ///
    4 "Deceased" 5 "ED Visit")) ///
    title("Types of study days for participants-Group 2", span) ytitle("Participant") xtitle("Day")

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float low2 int day double type float idreset
    0   1 0 1
    0   2 0 1
    0   3 6 1
    0   4 0 1
    0   5 0 1
    0   6 0 1
    0   7 0 1
    0   8 0 1
    0   9 0 1
    0  10 0 1
    0  11 1 1
    0  12 0 1
    0  13 0 1
    0  14 0 1
    0  15 0 1
    0  16 0 1
    0  17 0 1
    0  18 0 1
    0  19 1 1
    0  20 0 1
    0  21 0 1
    0  22 0 1
    0  23 0 1
    0  24 6 1
    0  25 0 1
    0  26 0 1
    0  27 2 1
    0  28 2 1
    0  29 2 1
    0  30 2 1
    0  31 2 1
    0  32 0 1
    0  33 0 1
    0  34 0 1
    0  35 0 1
    0  36 1 1
    0  37 1 1
    0  38 0 1
    0  39 1 1
    0  40 0 1
    0  41 0 1
    0  42 0 1
    0  43 0 1
    0  44 0 1
    0  45 0 1
    0  46 0 1
    0  47 0 1
    0  48 0 1
    0  49 0 1
    0  50 0 1
    0  51 0 1
    0  52 0 1
    0  53 0 1
    0  54 0 1
    0  55 0 1
    0  56 0 1
    0  57 0 1
    0  58 6 1
    0  59 0 1
    0  60 0 1
    0  61 2 1
    0  62 2 1
    0  63 2 1
    0  64 2 1
    0  65 2 1
    0  66 2 1
    0  67 2 1
    0  68 2 1
    0  69 2 1
    0  70 2 1
    0  71 2 1
    0  72 2 1
    0  73 2 1
    0  74 2 1
    0  75 2 1
    0  76 2 1
    0  77 2 1
    0  78 2 1
    0  79 2 1
    0  80 2 1
    0  81 2 1
    0  82 2 1
    0  83 2 1
    0  84 0 1
    0  85 0 1
    0  86 0 1
    0  87 0 1
    0  88 0 1
    0  89 0 1
    0  90 0 1
    0  91 0 1
    0  92 0 1
    0  93 3 1
    0  94 3 1
    0  95 3 1
    0  96 3 1
    0  97 3 1
    0  98 3 1
    0  99 3 1
    0 100 3 1
    end

  • #2
    The data example doesn't extend beyond day == 100 and you don't show your graph. So I have to guess at the problem here.. The help for axis scale options explains that


    range() never narrows the scale of an axis or causes data to be omitted from the plot.
    and this is the usual explanation for why it is ignored. So, what is the maximum value for day? xscale() will never obey a range() suboption call that includes a maximum less than the observed maximum.

    On the other hand

    Code:
    xla(0(10)180)
    should give labelled tick marks every 10 from 0 to 180. I would be more likely to go

    Code:
    xla(0(20)180) xtick(10(20)170)

    Comment


    • #3
      Hi Nick! Sorry about that. Here is my graph - the maximum value is 180 so it's not a matter of omitting data.

      Comment


      • #4
        Oops I see the graph that I copied didn't come through- I attached it here.
        Attached Files

        Comment


        • #5
          Sorry that line of code you sent worked- apologies for all of the posts!

          Comment


          • #6
            The graph helps -- but please note the request to show .png not .gph (FAQ Advice #12).

            Knowing that the maximum value of day is 180 permits a better story. There is no connection between xsc() and xla() and you needed to tune xlabel() directly to get different labels.

            I would

            use scheme(s1color) or some other scheme or otherwise lose the blue backdrop

            plot deceased by no colour at all, not a funereal black

            use yla(1 5 10 15, ang(h)) unless naturally you do have patient 0
            Last edited by Nick Cox; 28 Jan 2022, 12:23.

            Comment

            Working...
            X