Announcement

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

  • Stata: Combine graphs sharing one common y-axis

    Hello,

    I want to combine 2 or more graphs/plots [scatter plots, box plots, OLS regression lines, etc.] that show one common y-axis instead of replicating the y-axis for each graph.

    eg. I tried:

    graph box var1, saving(boxplot1.gph)
    graph box var1, over(group) saving(boxplot2.gph)
    gr combine boxplot1.gph boxplot2.gph

    It did combine the 2 boxplots but with 2 y-axes with exactly the same scales. How to show just one y-axis for both plots?

    I searched the Stata commands and the web but can't find what I want.

    Are there commands or coding convention to combine graphs and display just one common y-axis - not just for box plots but other types of graphs as well?

    Thanks in advance.

    Regards,

    Benjamin

  • #2
    In your case, there is an easy alternative. You want to show the box plots for each group, together with the box plot for everything combined.

    This is easy

    Code:
     
    sysuse auto, clear
    graph box mpg, by(foreign, total row(1))
    Consider also this example:

    Code:
    sysuse auto, clear
    preserve
    local Np1 = _N + 1
    expand 2
    replace foreign = 2 in `Np1'/L
    label def origin 2 "All", add  
    graph box mpg, over(foreign)
    restore
    Also http://www.stata-journal.com/article...article=gr0058

    Last edited by Nick Cox; 15 Dec 2014, 12:41.

    Comment


    • #3
      Hi Dr. Cox,

      It works! You are right, it's so easy.

      I will get a copy of your article as well.

      Thanks so much!

      Regards,

      Ben

      Comment

      Working...
      X