Announcement

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

  • Add padding to the x-axis in a twoway plot

    Hi

    I am struggling with adding padding to the x axis. I use the following code:


    Code:
    twoway ///
    (rcap low95 high95 row, vert) /// code for 95% CI
    (scatter proportion row if group ==1, mcolor(black)) /// dot for group 1
    , /// legend at 6 o'clock position
    xlabel(1 "Concentration" 2 "Progressive motile" 3 "Total sperm count" 4 "Motility (%)" 5 "Volume", angle(30) noticks) ///
    /// note that the labels are 1.5, 4.5, etc so they are between rows 1&2, 4&5, etc.
    /// also note that there is a space in between different rows by leaving out rows 3, 6, 9, and 12
    ylabel(0 "0" -5 "-5" -10 "-10" -15 "-15" -20 " -20" -25 "-25", angle(0)) /// no 1.6 label
    yline(0, lpattern(dash) lcolor(gs8)) ///
    /// aspect (next line) is how tall or wide the figure is
    aspect(0.7)

    I get the following graph
    Click image for larger version

Name:	Difference in sperm parameters snuff vs no  1.png
Views:	1
Size:	26.4 KB
ID:	1726410


    I would like to add padding before the concentration because as you see it is very close to the y axis, and I would also like to add padding after volume, Any idea how to do that?

    Also how do I remove the legend in the code?

    Cheers

  • #2
    For your future posts, include a data example using the dataex command that reproduces the graph (refer to FAQ Advice #12). See highlighted:

    Code:
    twoway ///
    (rcap low95 high95 row, vert) /// code for 95% CI
    (scatter proportion row if group ==1, mcolor(black)) /// dot for group 1
    , /// legend at 6 o'clock position
    xlabel(1 "Concentration" 2 "Progressive motile" 3 "Total sperm count" 4 "Motility (%)" 5 "Volume", angle(30) noticks) ///
    /// note that the labels are 1.5, 4.5, etc so they are between rows 1&2, 4&5, etc.
    /// also note that there is a space in between different rows by leaving out rows 3, 6, 9, and 12
    ylabel(0 "0" -5 "-5" -10 "-10" -15 "-15" -20 " -20" -25 "-25", angle(0)) /// no 1.6 label
    yline(0, lpattern(dash) lcolor(gs8)) ///
    xscale(range(0, 6)) ///
    legend(off) ///
    /// aspect (next line) is how tall or wide the figure is
    aspect(0.7)

    Comment


    • #3
      Hi

      Thank you for you reply, it made absolutely no difference. The legend is still there and there and "command xscale is unrecognized"

      Here is the data

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input byte(row group) double(proportion low95 high95)
      1 1 -16.05 -12.16 -19.83
      2 1 -22.81 -27.88 -17.94
      3 1 -19.05 -23.21 -15.18
      4 1   1.58   -.38   3.43
      5 1  -1.97  -3.77   -.55
      end

      Comment


      • #4
        It works out on my side. Copy and paste the exact output.

        Click image for larger version

Name:	Graph.png
Views:	1
Size:	23.3 KB
ID:	1726421

        Comment


        • #5
          You could also zap the x axis title with xtitle(“”)

          Comment


          • #6
            Thank you for your reply. I got it to work but now there is too much space on each side,it looks unnatural

            Comment


            • #7
              The range defines a continuous scale, so you should be able to manipulate the start and end points, e.g.,

              Code:
              xscale(range(0.5, 5.5))
              Last edited by Andrew Musau; 08 Sep 2023, 05:24.

              Comment


              • #8
                So try 0.5 to 5.5 as x range. Or exchange x and y axes (allowing horizontal text).

                Comment

                Working...
                X