Announcement

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

  • How to rotate Stata -by- group graph horizontally

    Hi Statalist members,

    I was wondering if there's a way to replicate this R gglot graph in Stata in terms of making the -by- variable display in a horizontal fashion instead of vertical.

    R ggplot here:
    Click image for larger version

Name:	Picture1.png
Views:	1
Size:	62.7 KB
ID:	1631649


    Example using Stata shows the -by- group in vertical:
    Code:
    webuse auto, clear
    recode rep78 (1/3 = 0 "M") (4/5 = 1 "F"), gen(gender)
    scatter weight length , by(gender) || lfitci weight length , by(gender, legend(off) note(" ")) col(%50) scheme(s1color) ylab(, grid) xlab(, grid) xsize(3)
    Stata scatter graph here:
    Click image for larger version

Name:	Picture2.png
Views:	1
Size:	95.6 KB
ID:	1631650

    How do I rotate the Stata graph to look like the R ggplot graph above?

    Thanks

  • #2
    As you scroll through the options in the output of help scatter you'll see twoway_options. Click on that and you'll find that the following will do what you want.
    Code:
    scatter weight length , by(gender, col(1)) || lfitci weight length , by(gender, legend(off) note(" ")) col(%50) scheme(s1color) ylab(, grid) xlab(, grid) xsize(3)

    Comment


    • #3
      Originally posted by William Lisowski View Post
      As you scroll through the options in the output of help scatter you'll see twoway_options. Click on that and you'll find that the following will do what you want.
      Code:
      scatter weight length , by(gender, col(1)) || lfitci weight length , by(gender, legend(off) note(" ")) col(%50) scheme(s1color) ylab(, grid) xlab(, grid) xsize(3)
      Thanks William for your response. Is there any way the rectangular box that houses the "M" and "F" groups can be switched to the right hand side of the y-axis as shown in the R ggplot2 example above?

      Comment


      • #4
        Code:
        sysuse auto, clear 
        recode rep78 (1/3 = 0 "M") (4/5 = 1 "F"), gen(gender)
        scatter weight length , by(gender, col(1)) subtitle(, pos(3) nobox nobexpand) || lfitci weight length , by(gender, legend(off) note(" ")) col(%50) scheme(s1color) ylab(, grid) xlab(, grid) xsize(3)

        Comment


        • #5
          Originally posted by Nick Cox View Post
          Code:
          sysuse auto, clear
          recode rep78 (1/3 = 0 "M") (4/5 = 1 "F"), gen(gender)
          scatter weight length , by(gender, col(1)) subtitle(, pos(3) nobox nobexpand) || lfitci weight length , by(gender, legend(off) note(" ")) col(%50) scheme(s1color) ylab(, grid) xlab(, grid) xsize(3)
          Thanks Nick

          Comment

          Working...
          X