Announcement

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

  • Highlight lines on spaghetti plot

    Hello,

    I am working with the following dataset.
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str10 study_id byte(time rand) float(ncpt min_compliance)
    "LEX-009" 1 0 107.11111 0
    "LEX-009" 2 0 115.77778 0
    "LEX-009" 3 0       116 0
    "LEX-011" 1 0  86.55556 0
    "LEX-011" 2 0  89.55556 0
    "LEX-011" 3 0         . 0
    "LEX-012" 1 0  87.66666 0
    "LEX-012" 2 0  89.77778 0
    "LEX-012" 3 0         . 0
    "LEX-013" 1 0  98.55556 0
    "LEX-013" 2 0  96.11111 0
    "LEX-013" 3 0  92.11111 0
    "LEX-014" 1 0  87.22222 1
    "LEX-014" 2 0 104.11111 1
    "LEX-014" 3 0 102.11111 1
    end
    I created spaghetti plots with the following code:

    Code:
    egen mean = mean(ncpt), by(rand time)
    separate mean, by(rand) veryshortlabel
    separate ncpt, by(rand) veryshortlabel
    sort study_id time
    set scheme s1color
    
    label def time 1 Baseline 2 "5 weeks" 3 "3 months"
    label val time time
    
    rename time Time
    
    line ncpt0 ncpt1 mean0 mean1 Time, c(L L L L)lc(red*0.2 blue*0.2 red blue) lw(medium medium medthick medthick) legend(order(3 "Training" 4 "Control" - "(Means thicker)") pos(3) col(1)) yla(, ang(h)) ytitle(NeuroCognitive Performance Test Score) xlabel(1 "Baseline" 2 "5 Week" 3 "3 Month")
    I would like to make the lines for the participants that min_compliance=1 stand out (either thicker or different color?). Is this possible?

    Thank you!
    Katie

  • #2
    Have 2 plots to distinguish these. Not tested.

    Code:
    tw (line ncpt0 ncpt1 mean0 mean1 Time if !min_compliance, c(L L L L) ///
    lc(red*0.2 blue*0.2 red blue) lw(medium medium medthick medthick)) ///
    (line ncpt0 ncpt1 mean0 mean1 Time if min_compliance, c(L L L L) ///
    lc(red*0.2 blue*0.2 red blue) lw(vthick vthick vthick vthick)) ///
    legend(order(3 "Training" 4 "Control" - "(Means thicker)") ///
    pos(3) col(1)) yla(, ang(h)) ytitle(NeuroCognitive Performance Test Score) ///
    xlabel(1 "Baseline" 2 "5 Week" 3 "3 Month"))

    Comment

    Working...
    X