Announcement

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

  • Large gap within yaxis in scatter plot

    Hello all,

    I'm working in this graph, but when I have few samples in y-axis a large gap appears between the samples in the graph. I tried everything from fixing sizes, margins and aspect ratio but I cannot find a coding solution for this.
    Could you help me?

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte parameter str4(first second) byte(first_xaxis second_xaxis)
    1 "red"  "blue" 0 1
    2 "blue" "red"  0 1
    end
    
    set scheme s2color
    
    gen yaxis = _n
    replace yaxis = yaxis - 1
        
    twoway (scatter yaxis first_xaxis if first == "blue", msymbol(O) mcolor(blue%30) msize(medlarge)) (scatter yaxis first_xaxis if first == "red", msymbol(O) mcolor(red%30) msize(medlarge)) (scatter yaxis second_xaxis if second == "blue", msymbol(O) mcolor(blue%30) msize(medlarge))  (scatter yaxis second_xaxis if second == "red", msymbol(O) mcolor(red%30) msize(medlarge)), /*
    
    */ yscale(range(0 1)) ytitle("", size(small))/*
    
    */ ylabel(0 "Sample 1" 1 "Sample 2", angle(0) labsize(vsmall) notick nogrid) /*
    
    */ xscale(range (0 1) titlegap(5)) xtitle("", size(small)) /*
    
    */ xlabel(0 "Parameter 1" 1 "Parameter 2", angle(vertical) labsize(vsmall) notick) /*
    
    */ leg(off)  graphregion(color(white))
    Click image for larger version

Name:	image_27385.png
Views:	1
Size:	22.5 KB
ID:	1665404


    When I have many samples, the graph aspect is fine as the Samples are evenly distribuited in the yaxis:

    Code:
    clear all
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte parameter str4(first second) byte(first_xaxis second_xaxis)
    1 "red"  "blue" 0 1
    2 "blue" "red"  0 1
    3 "blue" "red"  0 1
    4 "blue" "red"  0 1
    5 "blue" "red"  0 1
    6 "blue" "red"  0 1
    7 "blue" "red"  0 1
    8 "blue" "red"  0 1
    9 "blue" "red"  0 1
    10 "blue" "red"  0 1
    11 "blue" "red"  0 1
    end
    
    
    set scheme s2color
    
    gen yaxis = _n
    replace yaxis = yaxis - 1
      
    twoway (scatter yaxis first_xaxis if first == "blue", msymbol(O) mcolor(blue%30) msize(medlarge)) (scatter yaxis first_xaxis if first == "red", msymbol(O) mcolor(red%30) msize(medlarge)) (scatter yaxis second_xaxis if second == "blue", msymbol(O) mcolor(blue%30) msize(medlarge))  (scatter yaxis second_xaxis if second == "red", msymbol(O) mcolor(red%30) msize(medlarge)), /*
    
    */ yscale(range(0 10)) ytitle("", size(small))/*
    
    */ ylabel(0 "Sample 1" 1 "Sample 2", angle(0) labsize(vsmall) notick nogrid) /*
    
    */ xscale(range (0 1) titlegap(5)) xtitle("", size(small)) /*
    
    */ xlabel(0 "Parameter 1" 1 "Parameter 2", angle(vertical) labsize(vsmall) notick) /*
    
    */ leg(off)  graphregion(color(white))
    Click image for larger version

Name:	image_27386.png
Views:	1
Size:	30.9 KB
ID:	1665408


    I was able to artificially solve the problem by increasing the yscale without observations. This would solve the problem if I cut the graph using a image processing software, but I want to find a coding solution for this as this code will be inserted in a program:

    Code:
    clear all
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte parameter str4(first second) byte(first_xaxis second_xaxis)
    1 "red"  "blue" 0 1
    2 "blue" "red"  0 1
    end
    
    set scheme s2color
    
    gen yaxis = _n
    replace yaxis = yaxis - 1
        
    twoway (scatter yaxis first_xaxis if first == "blue", msymbol(O) mcolor(blue%30) msize(medlarge)) (scatter yaxis first_xaxis if first == "red", msymbol(O) mcolor(red%30) msize(medlarge)) (scatter yaxis second_xaxis if second == "blue", msymbol(O) mcolor(blue%30) msize(medlarge))  (scatter yaxis second_xaxis if second == "red", msymbol(O) mcolor(red%30) msize(medlarge)), /*
    
    */ yscale(range(0 10)) ytitle("", size(small))/*
    
    */ ylabel(0 "Sample 1" 1 "Sample 2", angle(0) labsize(vsmall) notick nogrid) /*
    
    */ xscale(range (0 1) titlegap(5)) xtitle("", size(small)) /*
    
    */ xlabel(0 "Parameter 1" 1 "Parameter 2", angle(vertical) labsize(vsmall) notick) /*
    
    */ leg(off)  graphregion(color(white))
    Click image for larger version

Name:	image_27387.png
Views:	1
Size:	22.6 KB
ID:	1665410

    Is there a way to remove this large gap between the observations when few itens are added in the y-scale? Or to cut the extra top space from my artifical solution?

    Thank you in advance,
    With the best wishes

    Rafael
    Last edited by Rafael Pacheco; 19 May 2022, 13:33.

  • #2
    a

    Comment


    • #3
      Not sure what you are looking for. Have you tried adding something like

      Code:
      aspect(0.1)
      in the first graph? If so, how is the result different from what you want?

      Comment


      • #4
        Does this work:

        Code:
        twoway scatter yaxis first_xaxis if first == "blue", msymbol(O) mcolor(blue%30)   msize(*5) /// 
            || scatter yaxis first_xaxis if first == "red", msymbol(O) mcolor(red%30)  msize(*5)  /// 
            || scatter yaxis second_xaxis if second == "blue", msymbol(O) mcolor(blue%30)  msize(*5)  /// 
            || scatter yaxis second_xaxis if second == "red", msymbol(O) mcolor(red%30)  msize(*5)   /// 
            || , ylabel(0 "Sample 1" 1 "Sample 2", angle(0) labsize(*2.5) notick nogrid)  /// 
                 xlabel(0 "Parameter 1" 1 "Parameter 2", angle(vertical)  labsize(*2.5) notick)  /// 
                 legend(off)  xsize(6) ysize(1.5)  ytitle("")
        Click image for larger version

Name:	Graph2.png
Views:	1
Size:	12.7 KB
ID:	1665428

        Comment


        • #5
          Originally posted by Andrew Musau View Post
          Not sure what you are looking for. Have you tried adding something like

          Code:
          aspect(0.1)
          in the first graph? If so, how is the result different from what you want?

          Dear Andrew,

          Yeah, this works.
          I was doing this with the inflated yscale, which obviously was not solving the problem.

          Sorry for the silly question.

          Best
          Rafael

          Comment

          Working...
          X