Announcement

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

  • graph combine and align x-axis

    Hi Listers,

    I'd like to combine a KM curve with associated risktable and one for smoothed hazard estimates; however, because of the risktable the x-axis of the first plot aresquashed.

    Is there any way I can have the two graphs aligned on the x-axis? any tip welcome

    I have used Stata sample data to show the code I am using and the figure:

    Code:
    webuse cancer, clear
    
    stset studytime died
    
    sts graph, risktable
    graph save  temp1.gph, replace
    
    sts graph, hazard
    graph save  temp2.gph, replace
    
    graph combine temp1.gph temp2.gph, col(1)
    Click image for larger version

Name:	plot.jpg
Views:	1
Size:	33.8 KB
ID:	1784755


    Thank you!!!

  • #2
    Experiment shows that the xcommon option doesn't help.

    There may well be a way to generate the results as new variables and proceed from there.

    Comment


    • #3
      Maybe something like:

      Code:
      webuse cancer, clear
      
      stset studytime died
      
      sts graph, risktable(, title(, at(20) justification(center)))
      graph save  temp1.gph, replace
      
      sts graph, hazard
      graph save  temp2.gph, replace
      
      graph combine temp1.gph temp2.gph, col(1)

      Comment


      • #4
        Hua Peng (StataCorp) Thanks for this, it worked. However, for a more complex plot (which is what I am after), the issue persist. Can the code be fixed? As Nick mentioned xcommon and ycommon don't fix the issue.

        Code:
        webuse cancer, clear
        
        stset studytime died
        
        sts graph, by(drug) risktable(, title(, at(20) justification(center)))
        graph save  temp1.gph, replace
        
        sts graph, by(drug) hazard
        graph save  temp2.gph, replace
        
        graph combine temp1.gph temp2.gph, col(1)
        Click image for larger version

Name:	test2.jpg
Views:	1
Size:	39.9 KB
ID:	1784775

        Comment


        • #5
          The titles in the risk table extend beyond the left margin of the first graph. You should impose a left margin on the second graph as well.


          Code:
          webuse cancer, clear
          
          stset studytime died
          
          sts graph, by(drug) risktable(, title(, at(20) justification(center)))
          graph save  temp1.gph, replace
          
          sts graph, by(drug) hazard ysc(outergap(20))
          graph save  temp2.gph, replace
          
          graph combine temp1.gph temp2.gph, col(1)
          Click image for larger version

Name:	Graph.png
Views:	1
Size:	42.7 KB
ID:	1784777

          Comment


          • #6
            Andrew Musau that worked perfectly - thank you very much!

            Comment


            • #7
              Would it look like better with the graphs in reverse order? (I sense that there is (bio)statistical logic to showing survival first; the point is essentially aesthetic.)

              Comment

              Working...
              X