Announcement

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

  • How to edit the position of y axis labels relative to the y axis of a scatter plot?

    I am new to Stata, and I need my graph to look like the following image (X-label removed for privacy reasons).
    Click image for larger version

Name:	Screenshot 2023-05-23 at 13.51.40.png
Views:	1
Size:	198.5 KB
ID:	1714567



    where the Y-labels are on the other side of the Y-axis. Currently, when I run my code (which is the same code with different values), the graph ends up this way:

    Click image for larger version

Name:	Screenshot 2023-05-23 at 13.52.54.png
Views:	1
Size:	775.3 KB
ID:	1714568






    My code is below:

    twoway (scatter A parameter, mc(sea)) (rcap Lower95confidencelimit Upper95confidencelimit A, horizontal lcolor(sea)), ysize(6) xsize(6) ylabel(1 "EQ-VAS < mean" 2 "EQ-VAS > mean" 3 "EQ-5D < mean" 4 "EQ-5D > mean" 5 "Other employment category not mentioned" 6 "Retired" 7 "Military" 8 "Student" 9 "Unable to work" 10 "Unemployed" 11 "Employed" 12 "Net monthly income prefer not to say" 13 "Net income above $100,000" 14 "Net income $75,000-$99,999" 15 "Net income $50,000-$74,999" 16 "Net income $35,000-$49,999" 17 "Net income $20,000-$34,999" 18 "Net income less than $20,000" 19 "Fairly (easy) to make ends meet" 20 "Some/great difficulty making ends meet" 21 "Education high" 22 "Education mid" 23 "Education low" 24 "Age 65-75" 25 "Age 55-64" 26 "Age 45-54" 27 "Age 35-44" 28 "Age 25-34" 29 "Age 18-24", angle(0) noticks) ytitle("") xtitle("Total") xlabel(15 "15" 20 "20" 25 "25" 30 "30" 35 "35 " 40 "40" 45 "45 " 47 " " , angle(0)) legend(off)



    I have tried editing the axis properties in the graph editor and nothing seems to change. Both graphs have the exact same code, just different data sets and labels, so I am unsure why the y-label position is different.


  • #2
    It's hard to give advice without the data.

    Comment


    • #3
      Unfortunately I can't give the data because it's protected under privacy. But the code is exactly the same as the first graph and the range of data is relatively similar as well, so I can't see a reason that the graphs would be different when the data sets are also not that different.

      Comment


      • #4
        We certainly don't expect you to show confidential or sensitive data, but this common constraint is already discussed in the FAQ Advice for Statalist: https://www.statalist.org/forums/help#stata

        If your dataset is confidential, then provide a fake example instead.
        My guess from experience is that you are trying to squeeze a lot of data into the graph, including some long axis labels.

        My attempts to reproduce your problem failed, however. Here is my fake with the same number of observations and axis labels varying in length but the longest the same text as your longest.


        Code:
        clear 
        
        set obs 29 
        gen label = "Other employment category not mentioned" in 1
        replace label = substr("Other employment category not mentioned", 1, _n) in 2/L 
        gen parameter = runiformint(1, 10)
        gen lower = parameter - 1 
        gen upper = parameter + 1 
        gen A = _n 
        * labmask is from the Stata Journal; it's not important to you as you have the real data or can spell out labels one by one 
        labmask A, values(label)
        
        scatter A parameter, yla(1/29, valuelabel noticks) || ///
        rcap lower upper A, horizontal legend(off)
        The result isn't pretty but it is not grotesque:

        Click image for larger version

Name:	cantreproduce.png
Views:	1
Size:	76.2 KB
ID:	1714689

        Now

        1. I am using Stata 18. See the Statalist FAQ on stating earlier versions of Stata. I have to doubt that this is the issue. But you can try a version of the code above in your Stata.

        2. I didn't specify above ysize(6) xsize(6) but when I also do that the data region is reduced unacceptably -- yet I don't see the problem you report.

        3. There are some other details in your syntax that I didn't play with but doubt are important.

        Comment

        Working...
        X