Announcement

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

  • Twoway scatter plot: how to modify axis length

    Hello,

    This is my first post here so if I did something wrong I apologize.

    I'm working with a dataset from Comtrade, specifically with information about trade values between Italy, Belgium, Mexico, Israel, Japan and USA. I was trying to make the same graph (Graph 1) and I almost get it. The problem is that I don't know how to put together both x axis and y axis (from the origin) in order to have no space after the beginning.

    I run the following code:

    twoway scatter porcentaje_com porcentaje_pib, title(" ", margin(b=1)) mlabel(reporter) mlabcolor(black) mlabv(pos) graphregion(fcolor(white)) ytitle("Porcentaje del comercio" " estadounidense con la UE", orientation(horizontal) margin(0 -35 80 0) size(small)) ylab(, ang(hor) labsize(small)) xtitle("Porcentaje del PIB de la UE", margin(0 -45 0 0) size(small)) xlab(, labsize(small)) legend(off) mcolor(ebblue) msize(small) || function y=x, range(0 25) n(2) aspect(1) lcolor(black)

    And I got the Graph 2

    I hope you understand my question.

    Thanks!

    PD: the idea is basically to force the line to touch both margins.
    Attached Files

  • #2
    Try adding xsc(r(0 25)) as option.

    xsc is short for xscale, which defines the scale for axis y. r(0 25) means "range from 0 to 25".

    Comment


    • #3
      Joao,

      I added xsc(r(0 25)) as option but it didn't work. I don't know if I explained myself well but I want to force the 45 degree line to touch both margins as Graph 1

      Comment


      • #4
        This is hard to follow. No data example, different data in two graphs, etc. I don't know what "touch both margins" means unless that refers to corners (vertices). But two principles:

        1. Stata won't omit data points because of axis scale or axis label choices.

        2. If you want a line of equality as diagonal from bottom left to top right you need something more like xsc(r(0 80)) ysc(r(0 80)) aspect(1) and range(0 80) on the function,

        Comment


        • #5
          Nick,

          I'm sorry. I'll try to explain it better.

          It doesn't matter both graphs differ in data. I just want to force the 45 degree line to touch both the origin (the problem in my graph is that both 0 axis don't match as graph 1) and the right margin.
          I tried with your code, which was correct by the way, but I don't want to change the slope.

          PD: if you see Graph 1, the corner exactly starts from both 0 axis. In contrast, Graph 2 (my output) starts from something before 0.
          Attached Files

          Comment


          • #6
            See https://www.statalist.org/forums/for...rgin-in-a-plot

            Comment


            • #7
              Nick,

              It worked! Thank you so much

              Comment

              Working...
              X