Announcement

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

  • Value size in heatplot

    I am trying to generate a heatplot with flags for significant correlations.

    It looks great :-) using this code:

    sysuse auto, clear

    pwcorr price mpg trunk weight length turn foreign, sig

    matrix C = r(C)
    matrix sig = r(sig)

    heatplot C, values (label(sig)) lower nodraw generate
    // significance stars
    gen str sig = cond(_Mlab<.05, "*", "")

    heatplot C, legend(off) color(hcl diverging, intensity(.6)) lower aspectratio(1) ///
    addplot(scatter _Y _X if _Y!=_X, msym(i) mlab(_Z) mlabf(%9.1f) mlabpos(0) mlabc(black) ///
    || scatter _Y _X if _Y==_X, msym(i) mlab(_Z) mlabf(%9.0f) mlabpos(0) mlabc(black) ///
    || scatter _Y _X if _Y!=_X, msym(i) mlab(sig) mlabpos(2) mlabgap(2) mlabc(black))

    Click image for larger version

Name:	Auto.png
Views:	1
Size:	69.7 KB
ID:	1779236

    However, I have many more variables in my dataset, 39 variables. I can create a nice heatplot without the significance stars, by changing the size:

    pwcorr var1, var2, var3, etc...
    return list
    matrix corrmatrix = r(C)
    heatplot corrmatrix, values(format(%4.1f) size(1.1)) legend(off) color(hcl diverging, intensity(.7)) aspectratio(1) xlabel(,labsize(1.5) angle(90)) ylabel(,labsize(1.5)) lower nodiagonal

    Click image for larger version

Name:	Heat without significance.png
Views:	1
Size:	222.7 KB
ID:	1779237

    I would be grateful if someone can help me create a code including the significance marker and the smaller text. When adding the size option to the first, or second "heatplot C" it still does not give smaller size.

    pwcorr var1, var2, var3, etc...

    return list

    matrix C = r(C)
    matrix sig = r(sig)

    heatplot C, values (label(sig)) lower nodraw generate
    // significance stars
    gen str sig = cond(_Mlab<.05, "*", "")

    heatplot C, legend(off) color(hcl diverging, intensity(.6)) lower aspectratio(1) xlabel(,labsize(1.5) angle(90)) ylabel(,labsize(1.5)) ///
    addplot(scatter _Y _X if _Y!=_X, msym(i) mlab(_Z) mlabf(%9.1f) mlabpos(0) mlabc(black) ///
    || scatter _Y _X if _Y==_X, msym(i) mlab(_Z) mlabf(%9.0f) mlabpos(0) mlabc(black) ///
    || scatter _Y _X if _Y!=_X, msym(i) mlab(sig) mlabpos(2) mlabgap(2) mlabc(black))

    Click image for larger version

Name:	Correlations H70.png
Views:	1
Size:	427.4 KB
ID:	1779238

  • #2
    I don't think the answer is specific to heatplot at all, or at least my answer isn't.

    Unless you are going to print the graph on a large piece of paper or equivalent for physical display the scope to make that readable seems minimal. Sorry, but tweaking details won't change anything of importance, unless I am completely misunderstanding the question.

    Comment


    • #3
      Dear Nick,

      The question is if its possible to change the font size in the graph. How do i do that? I am aware if potential readability problems in in the graph i attached. Maybe in the example from the auto dataset, can you suggest how to make the text bigger in this code?

      sysuse auto, clear

      pwcorr price mpg trunk weight length turn foreign, sig

      matrix C = r(C)
      matrix sig = r(sig)

      heatplot C, values (label(sig)) lower nodraw generate
      // significance stars
      gen str sig = cond(_Mlab<.05, "*", "")

      heatplot C, legend(off) color(hcl diverging, intensity(.6)) lower aspectratio(1) ///
      addplot(scatter _Y _X if _Y!=_X, msym(i) mlab(_Z) mlabf(%9.1f) mlabpos(0) mlabc(black) ///
      || scatter _Y _X if _Y==_X, msym(i) mlab(_Z) mlabf(%9.0f) mlabpos(0) mlabc(black) ///
      || scatter _Y _X if _Y!=_X, msym(i) mlab(sig) mlabpos(2) mlabgap(2) mlabc(black))

      Comment


      • #4
        Isn't is enough to add
        Code:
        mlabsize(tiny)
        to your scatter-code? Like:
        Code:
        heatplot C, legend(off) color(hcl diverging, intensity(.6)) lower aspectratio(1) ///
        addplot(scatter _Y _X if _Y!=_X, msym(i) mlab(_Z) mlabf(%9.1f) mlabpos(0) mlabc(black) mlabsize(tiny) ///
        || scatter _Y _X if _Y==_X, msym(i) mlab(_Z) mlabf(%9.0f) mlabpos(0) mlabsize(tiny) mlabc(black) ///
        || scatter _Y _X if _Y!=_X, msym(i) mlab(sig) mlabpos(2) mlabgap(2) mlabsize(tiny) mlabc(black))

        Comment


        • #5
          It worked! Thank you so much!!
          Click image for larger version

Name:	Heatplot with significance markers.jpg
Views:	1
Size:	296.6 KB
ID:	1779629

          Comment

          Working...
          X