Announcement

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

  • Adjust space between plots in "twoway ...., by(group)"

    I created two scatterplots and plotted them side by side, using
    "twoway (scatter y x), by(binary_group_var)"

    The resulting graph looks like the first figure in https://stats.idre.ucla.edu/stata/mo...atter-combine/, which is copied here for convenience.

    Capture.PNG

    I'd like to know how to modify the command above to adjust the spacing between the two scatterplots. Specifically, I want to widen the distance between the two plots.

    Thank you.

  • #2
    I also have the same question. Is there any help available on this issue?

    Comment


    • #3
      Documented suboptions compact and imargin() at

      Code:
      help by option 
      
      * also 
      help marginstyle
      Examples:

      Code:
      . sysuse auto, clear
      (1978 automobile data)
      
      . scatter mpg weight, by(foreign)
      
      .. scatter mpg weight, by(foreign, imargin(large))
      
      . scatter mpg weight, by(foreign, imargin(zero))

      Comment


      • #4
        Thanks Nick. I am getting an error when trying to do this with twoway. Code and error below.

        Code:
        mylabels 0(0.02)0.08, format(%04.3f) clean local(labels)
        twoway (histogram speed if winter_2020==1, by(cityname_corrected, note("") imargin(large)) yla(`labels') color(blue%40) subtitle(, fcolor(white) lstyle(none))) ///        
               (histogram speed if winter_2020==0, by(cityname_corrected, note("") imargin(large)) yla(`labels') color(yellow%60) subtitle(, fcolor(white) lstyle(none))), ///   
               legend(order(1 "Jan to March 2020" 2 "April to June 2020" ) region(lstyle(none))) ysize(5)
        Error:

        Code:
        option imargin() not allowed
        r(198);

        Comment


        • #5
          There is no data example here, so your code cannot be run, but I can reproduce the error with the command commented out below and fix it with the following command.

          I think graph is just confused about what you want.

          mylabels is from SSC, as you are asked to explain, but irrelevant here,

          It's always a good idea to reduce problematic code to a minimal reproducible example, as is flagged elsewhere: https://stackoverflow.com/help/minim...ucible-example


          Code:
          sysuse auto, clear 
          
          * twoway (histogram mpg if rep78 <= 3, by(foreign, note("") imargin(large))) ///        
                 (histogram mpg if rep78 > 3,  by(foreign, note("") imargin(large)))
                   
           twoway (histogram mpg if rep78 <= 3, by(foreign, note("") imargin(large))) ///        
                 (histogram mpg if rep78 > 3)

          Comment


          • #6
            Originally posted by Nick Cox View Post
            There is no data example here, so your code cannot be run, but I can reproduce the error with the command commented out below and fix it with the following command.

            I think graph is just confused about what you want.

            mylabels is from SSC, as you are asked to explain, but irrelevant here,

            It's always a good idea to reduce problematic code to a minimal reproducible example, as is flagged elsewhere: https://stackoverflow.com/help/minim...ucible-example


            Code:
            sysuse auto, clear
            
            * twoway (histogram mpg if rep78 <= 3, by(foreign, note("") imargin(large))) ///
            (histogram mpg if rep78 > 3, by(foreign, note("") imargin(large)))
            
            twoway (histogram mpg if rep78 <= 3, by(foreign, note("") imargin(large))) ///
            (histogram mpg if rep78 > 3)
            Thank you so much!

            Comment

            Working...
            X