Announcement

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

  • Graph of individual patient values over time.

    Dear Statalist members
    I have this dataset with 3 patients, wherein "lad" has been measured over 5 follow-up times. The data is as below:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(sno followup) double lad
     9 0 5.5
     9 1 5.1
     9 2 4.9
     9 3 4.8
     9 4 5.6
    13 0 5.8
    13 1 5.4
    13 2 4.9
    13 3 4.8
    13 4 5.6
    24 0 5.8
    24 1 5.7
    24 2 5.4
    24 3 5.4
    24 4 4.3
    end
    label values followup followup
    label def followup 0 "Pre-PTCM", modify
    label def followup 1 "Immediate Post-PTCM", modify
    label def followup 2 "1 Year Post-PTCM", modify
    label def followup 3 "Three Year Post-PTCM", modify
    label def followup 4 "Five Year Post-PTCM", modify
    I want to make a graph which looks like this graph below. I have made this graph in Microsoft Excel. How can I make a similar graph in Stata?
    Click image for larger version

Name:	lad.jpg
Views:	1
Size:	274.6 KB
ID:	1751986

  • #2
    Something like this?

    Code:
    twoway scatter lad followup, ///
        connect(l) ///
        mlabel(lad) ///
        xlabel(, valuelabel labsize(small)) ylabel(none) ///
        xscale(range(0 4.5)) ///
        colorvar(sno) colordiscrete colorlist(green orange blue) ///
        coloruseplegend ///
        plegend(rows(1) pos(6) title("Patient", pos(9) size(medsmall))) ///
        title("LAD") ytitle("") xtitle("") ///
        scheme(stcolor)
    which produces:
    Attached Files

    Comment


    • #3
      Thank you very much Hemanshu Kumar
      I should have mentioned the Stata version I am using. I have Stata 17.0
      Option colorvar is not available in Stata 17.0, it seems.
      Last edited by Inaamul Haq; 02 May 2024, 01:01.

      Comment


      • #4
        This should work in Stata 17:

        Code:
        twoway connected lad followup if sno == 9, lc(green) mc(green) mlabel(lad) mlabc(green) ///
            || connected lad followup if sno == 13, lc(orange) mc(orange) mlabel(lad) mlabc(orange) ///
            || connected lad followup if sno == 24, lc(blue) mc(blue) mlabel(lad) mlabc(blue) ///
            xlabel(, valuelabel labsize(small)) ylabel(none) ///
            xscale(range(0 4.5)) ///
            legend(rows(1) order(1 "Patient 9" 2 "Patient 13" 3 "Patient 24") pos(6) size(medsmall)) ///
            title("LAD") ytitle("") xtitle("") ///
            scheme(stcolor)

        Comment


        • #5
          (This was a long time in writing given other tasks, so I didn't see #4 until I posted it.)

          This should work in version 17. I haven't followed the prescription exactly.

          There is a case that if you show the measurements as marker labels you don't need the vertical axis labels, but they do no harm and may help some readers, particularly as (evidently) it is not helpful to start the y axis at 0.

          Note that measurements for two patients coincide at some times.

          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input byte(sno followup) double lad
           9 0 5.5
           9 1 5.1
           9 2 4.9
           9 3 4.8
           9 4 5.6
          13 0 5.8
          13 1 5.4
          13 2 4.9
          13 3 4.8
          13 4 5.6
          24 0 5.8
          24 1 5.7
          24 2 5.4
          24 3 5.4
          24 4 4.3
          end
          label values followup followup
          label def followup 0 "Pre-PTCM", modify
          label def followup 1 `" "Immediate" "Post-PTCM" "', modify
          label def followup 2 `" "1 Year" "Post-PTCM" "', modify
          label def followup 3 `" "Three Year" "Post-PTCM" "', modify
          label def followup 4 `" "Five Year" "Post-PTCM" "', modify
          
          separate lad, by(sno) veryshortlabel
          
          twoway connect `r(varlist)' followup, ///
              mlabel(lad lad lad) mlabcolor(green orange blue) mlabpos(1 ..) ///
              ms(O D T) xlabel(, valuelabel labsize(small)) ylabel(4(0.5)6, ang(h)) ///
              xscale(range(0 4.5)) ///
              lc(green orange blue) mc(green orange blue) ///
              legend(ring(0) rows(3) order(3 2 1) pos(7) title("Patient", pos(12) size(medsmall))) ///
              title("LAD") ytitle("units of measurement belong here") xtitle("") ///
              scheme(s1color)

          Axis titles and labels, marker label positions, legend position and layout all need to be thought about. I prefer direct labelling to legends in which identifiers appear on the graph, usually at the end of each series, but that would not work well for these patients.
          Click image for larger version

Name:	lad_line.png
Views:	1
Size:	52.2 KB
ID:	1752012

          Comment

          Working...
          X