Announcement

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

  • Dot/before and after plot

    Hi,

    I'm wanting to compare continuous values before a stenting procedure, and continuous values after this procedure. Patients with artery narrowing have this assessed by measuring the velocity of blood through this narrowing (peak systolic velocity (PSV)). I have 2 main cohorts of patients within my population: ones with calcified arteries, and ones without calcium deposits in their arteries. I want to display these differences similar to this following graph published in this paper:

    Click image for larger version

Name:	dot.png
Views:	1
Size:	67.9 KB
ID:	1750542


    (Published in Mitchell EL, Chang EY, Landry GJ, Liem TK, Keller FS, Moneta GL. Duplex criteria for native superior mesenteric artery stenosis overestimate stenosis in stented superior mesenteric arteries. Journal of Vascular Surgery. 2009 Aug;50(2):335–40. doi:10.1016/j.jvs.2008.12.071). Note, the authors created this using SPSS.


    This is my data:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte calc int(pre post)
    0 600 372
    1 380 300
    0 647 244
    1 472 112
    0 336 276
    0 360 420
    1 500 500
    1 455 217
    0 250 100
    0 500   0
    0 600 500
    0 350 137
    end

    The calcification status is denoted by calc; present (1) and absent (0), and pre and post denote the pre-stenting PSV and post-stenting PSV.

    The following code:
    Code:
    graph dot (asis) pre post, over(calc)
    brings this error: variables calc and _variables do not uniquely identify the observations
    r(459);

    I came across -pairplot-
    And inputted the following:
    Code:
    pairplot pre post calc
    which generated the following plot:

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	45.9 KB
ID:	1750541


    My other idea is if I rearrange the data so that all PSVs are in a single column, have a neighbouring column denote if it's a pre or post value, generate a simple scatterplot with calcified patients marked as an X and non-calcified patients marked as an O, and just manually connect the pre and post PSVs. But before I try that I want to put out a final feeler if there's a way to do all this through Stata! My end goal here is to either generate a single plot with calc/non-calc denoted with Xs and Os and with say a blue line for calc and red for non calc patients, or have a graph similar to the one published where the x-axis is longer and the pre and post values for calc and non-calc are shown side by side.

    Thanks!

  • #2
    Is each observation in your data a patient? For example:

    0 600 372
    is patient 1

    1 380 300
    is patient 2 and so on?

    Comment


    • #3
      Originally posted by Ashar Asif View Post
      I want to display these differences similar to this following graph
      . . . or have a graph similar to the one published where the x-axis is longer and the pre and post values for calc and non-calc are shown side by side.
      I believe that it's often called a spaghetti plot.
      Code:
      search spaghetti
      will bring up some useful links.

      pairplot is a user-written command. xtline is official, but might prove more awkward to use for your purpose.

      You can manually create side-by-side graphs of spaghetti plots of the two diagnostic conditions. Perhaps something like the following.
      Code:
      version 18.0
      
      clear *
      
      input byte calc int(pre post)
      0 600 372
      1 380 300
      0 647 244
      1 472 112
      0 336 276
      0 360 420
      1 500 500
      1 455 217
      0 250 100
      0 500   0
      0 600 500
      0 350 137
      end
      
      generate byte pid = _n
      rename (pre post) psv#, addnumber(0)
      quietly reshape long psv, i(pid) j(tim)
      
      // As before
      summarize psv, meanonly
      quietly replace psv = r(max) if psv == 0
      
      quietly levelsof pid, local(pids)
      foreach pid of local pids {
          local plots `plots'  connected psv tim if pid == `pid' & !calc, ///
              lcolor(black) mcolor(black) msize(small) ||
      }
      graph twoway ///
          `plots' || ///
          scatter psv tim if 1 == 0, yline(275, lcolor(black) lpattern(dash)) ///
          ytitle(Peak Systolic Velocity (cm/s)) ylabel( , angle(horizontal) nogrid) ///
          xtitle("") xlabel(-0.1 " " 0 "Before" 1 "After" 1.1 " ", noticks) ///
          scheme(s2color) legend(off) name(Without)
      
      local plots
      foreach pid of local pids {
          local plots `plots'  connected psv tim if pid == `pid' & calc, ///
              lcolor(black) msymbol(T) mcolor(black) msize(medsmall) ||
      }
      graph twoway ///
          `plots' || ///
          scatter psv tim if 1 == 0, yline(275, lcolor(black) lpattern(dash)) ///
          ytitle(Peak Systolic Velocity (cm/s), color(ltbluishgray)) ///
              ylabel( , angle(horizontal) nogrid) ///
          xtitle("") xlabel(-0.1 " " 0 "Before" 1 "After" 1.1 " ", noticks) ///
          scheme(s2color) legend(off) name(With)
      
      graph combine Without With, ycommon
      
      exit

      Comment


      • #4
        As Joseph Coveney implies and exemplifies there are many ways to approach graphing such data.



        pairplot is from SSC and is mine. You'd be better off starting with

        Code:
        pairplot pre post
        Otherwise see e.g.

        Code:
        SJ-9-4  gr0041  . . . . . . Speaking Stata: Paired, parallel, or profile plots
                . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
                Q4/09   SJ 9(4):621--639                                 (no commands)
                explores paired, parallel, and profile plot making for
                changes, correlations, and other comparisons between
                variables
        
        SJ-5-2  gr0015  . . . . . . . . Stata tip 21: The arrows of outrageous fortune
                . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
                Q2/05   SJ 5(2):282--284                                 (no commands)
                tip for using graph twoway pcarrow for graphing changes
                over time
        
        
        SJ-4-3  gr0005  . . . . .  Speaking Stata: Graphing agreement and disagreement
                . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
                Q3/04   SJ 4(3):329--349                                 (no commands)
                how to select the right graph to portray comparison or
                assessment of agreement or disagreement between data
                measured on identical scales
        This is similar to the graph you show.


        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input byte calc int(pre post)
        0 600 372
        1 380 300
        0 647 244
        1 472 112
        0 336 276
        0 360 420
        1 500 500
        1 455 217
        0 250 100
        0 500   0
        0 600 500
        0 350 137
        end
        
        gen id = _n
        
        rename (pre post) (v1 v2)
        
        reshape long v, i(id) j(time)
        
        label def time 1 pre 2 post
        
        label val time time
        
        label def calc 1 calcified 0 "not calcified"
        
        label val calc calc
        
        twoway connected v t, c(L) xla(1 2, valuelabel)  ytitle(Peak systolic velocity (cm s{sup:-1})) by(calc, note("")) xtitle("")
        Click image for larger version

Name:	psv.png
Views:	1
Size:	70.9 KB
ID:	1750561



        My guess is that superimposing the two groups wouldn't help much, especially if you really have many more patients.

        Comment


        • #5
          Joseph Coveney and Nick Cox That is exactly what I am looking for, thank you!

          Comment

          Working...
          X