Announcement

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

  • Heatplot - value labels not shown

    Dear all,

    I am writing here becasue it seems to me that this issue has not been addressed previously.

    I am creating a heatmap using heatplot, but I am failing to plot the (previoulsy encoded) value labels of my y-axis variable. It is interesting that this instead works when I use twoway contour. I initially thought that there was an issue in my data, but the same applies when I use the dataset auto2. Specifically:

    Code:
    sysuse auto2, clear
    
    
    heatplot price rep78 foreign, ylabel(1(1)5, valuelabel)
    Produces the following output:





    Whereas when I use

    Code:
    twoway contour price rep78 foreign, heatmap ylabel(1(1)5, valuelabel)
    I manage to obtain the correct value labels:




    Is anyone able to explain why this happens? Maybe the command heatplot does not support the "valuelabel" option?
    In any case, could anyone please help in fixing the issue with "heatplot"? For my specific data it seems to me that heatplot is a more flexible command than twoway contour.

    Thank you in advance.

  • #2
    heatplot is from SSC, as you are asked to explain (FAQ Advice #12). You may want to notify the author Ben Jann so that he takes a look at it. Also, use factor variable notation to reference categorical variables. Here is a workaround, provided that all levels of the categorical variable are observed.

    Code:
    sysuse auto2, clear
    set scheme s1color
    local labels
    local lvar rep78
    qui levelsof `lvar', local(labs)
    foreach lab of local labs{
        local labels `labels' `lab' `"`:label (`lvar') `lab''"'
    }
    heatplot price i.rep78 i.foreign, xlab(1 "Domestic" 2 "Foreign", noticks) ylabel(`labels', noticks)
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	19.4 KB
ID:	1728402

    Last edited by Andrew Musau; 27 Sep 2023, 10:23.

    Comment


    • #3
      Hi Andrew Musau thank you very much for your help, it works perfectly! The label shortcut with the loop is extremely felixible and can be applied to several related situations.

      It would be interesting to know whether the author was aware of this.

      Comment


      • #4
        Hi, if you declare variables as categorical, heatplot will pick up the labels, such that the workaround by Andrew does not seem to be needed. Example;

        Code:
        sysuse auto2, clear
        heatplot price i.rep78 i.foreign
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	161.2 KB
ID:	1728487


        If you want to omit the ticks and grid lines, you could type:

        Code:
        heatplot price i.rep78 i.foreign, ylab(, notick nogrid) xlab(, notick nogrid)
        ben

        Comment


        • #5
          Ben Jann thank you very much for your reply. this is useful!

          Apologies for not finding out about the availability of the labels when using categorical variables, but in my specific case I initially thought it was best not to use them. I am reconsidering that option now.

          Comment

          Working...
          X