Announcement

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

  • heatplot spearman correlation, colours

    Hello, does anyone know how to change the colour palette for heatplot so Stata uses shades of blue for negative correlations, shades of red for positive correlations, and 0 = white? I am now using

    Code:
    color(hcl blured)
    but it drives me crazy that 0 is not assigned to white, aka the cutoff between red and blue.

    Thank you!

    Code:
    en touse = !missing(SWLS, Sleepquality, Sleepduration, Sleephygiene, Bedtimeprocrastination, Age, Education, EmploymentStatus, Income, LivingSituation, Nightshift, Kids)
    
    foreach v in SWLS Sleepquality Sleepduration Sleephygiene Bedtimeprocrastination Age Education EmploymentStatus Income LivingSituation Nightshift Kids {
       egen rank_`v'  = rank(`v') if touse
    }
    
    pwcorr rank_SWLS rank_Sleepquality rank_Sleepduration rank_Sleephygiene rank_Bedtimeprocrastination rank_Age rank_Education rank_EmploymentStatus rank_Income rank_LivingSituation rank_Nightshift rank_Kids, sig
    matrix C = r(C)
    matrix sig = r(sig)
    heatplot C, values(label(sig)) lower nodraw nodiagonal generate
    gen str lab = string(_Z, "%4.3f") + ///
        cond(_Mlab<.001, "***", cond(_Mlab<.01, "**", cond(_Mlab<.05, "*", "")))
    
    heatplot C, color(hcl bluered) lower aspectratio(1) xlabel(, labsize(tiny) angle(45)) ylabel(, labsize(tiny))  nodiagonal ///
        addplot(scatter _Y _X, msymbol(i) mlab(lab) mlabpos(0) mlabcolor(black) mlabsize(tiny))
    Attached Files

  • #2
    It's fine to start a new thread with a precise and different question, but you should give a cross-reference to the old thread and post a diversion notice.

    https://www.statalist.org/forums/for...an-correlation

    As said there I can't recollect using heatplot so I could only answer this by reading the help file and experimenting with option choices. Someone ellse may have a quick answer.

    I wrote a corrtable in this territory a while back for a friend. I don't use it myself. It was written long before heatplot and has only loosely similar goals. You may want to have a quick look. It's on SSC.

    Comment


    • #3
      As always, you will increase your chances of getting helpful replies by enclosing a reproducible example. See FAQ Advice #12 for details.

      Comment

      Working...
      X