Announcement

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

  • Relative frequency in heatplot

    Hi there,

    Is it possible to create a heatplot that displays relative frequencies within each row?
    By default, heatplots display absolute frequencies, I mean, each value in the plot is the cell count (intersection) divided by the total number of observations.
    But i need that the plot display every value cell as the coefficient between the intersection and the total number of the row.

    A data example:

    clear
    input float(destino_or_a3 destino_or)
    1 5
    4 3
    3 1
    5 1
    5 5
    3 3
    4 1
    5 1
    4 3
    5 4
    5 5
    5 5
    4 1
    4 1
    5 4
    5 3
    3 3
    4 4
    4 4
    4 1


    Thanks !!
    Last edited by sladmin; 30 Jan 2026, 14:55. Reason: Anonymize original poster

  • #2
    Originally posted by Guest
    By default, heatplots display absolute frequencies, I mean, each value in the plot is the cell count (intersection) divided by the total number of observations.
    But i need that the plot display every value cell as the coefficient between the intersection and the total number of the row.
    The last statement is not entirely clear to me, but you could always calculate the relative frequencies and add them as a third variable in the graphing command.The following uses heatplot from SSC.

    Code:
    clear
    input float(destino_or_a3 destino_or)
    1 5
    4 3
    3 1
    5 1
    5 5
    3 3
    4 1
    5 1
    4 3
    5 4
    5 5
    5 5
    4 1
    4 1
    5 4
    5 3
    3 3
    4 4
    4 4
    4 1
    end
    
    bys destino_or_a3 destino_or: gen count=_N
    bys destino_or_a3: gen percent= (count/_N)*100
    heatplot percent destino_or_a3 destino_or, discrete xlab(1/5, noticks) ylab(1/5, noticks)
    Res.:

    Code:
    . l, sepby(destino_or_a3 destino_or)
    
         +----------------------------------------+
         | destin~3   destin~r   count    percent |
         |----------------------------------------|
      1. |        1          5       1        100 |
         |----------------------------------------|
      2. |        3          1       1   33.33333 |
         |----------------------------------------|
      3. |        3          3       2   66.66666 |
      4. |        3          3       2   66.66666 |
         |----------------------------------------|
      5. |        4          1       4         50 |
      6. |        4          1       4         50 |
      7. |        4          1       4         50 |
      8. |        4          1       4         50 |
         |----------------------------------------|
      9. |        4          3       2         25 |
     10. |        4          3       2         25 |
         |----------------------------------------|
     11. |        4          4       2         25 |
     12. |        4          4       2         25 |
         |----------------------------------------|
     13. |        5          1       2         25 |
     14. |        5          1       2         25 |
         |----------------------------------------|
     15. |        5          3       1       12.5 |
         |----------------------------------------|
     16. |        5          4       2         25 |
     17. |        5          4       2         25 |
         |----------------------------------------|
     18. |        5          5       3       37.5 |
     19. |        5          5       3       37.5 |
     20. |        5          5       3       37.5 |
         +----------------------------------------+
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	20.2 KB
ID:	1783071

    Last edited by sladmin; 30 Jan 2026, 14:56. Reason: Anonymize original poster

    Comment


    • #3
      Andrew, thanks.

      I solved it making a matrix and later the heatplot.

      Comment

      Working...
      X