Announcement

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

  • Advanced Heatmap

    Good morning,

    I have three string variables. I would like A and B to be categorical, while Cnum showing the count for that row. I want to create a heatmap so A and B form the matrix and the Cnum are counts

    See data example below.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str107 A str168 B byte Cnum
    "Raw materials production"                                                           "Emitted greenhouse gas emissions" 0
    "Raw materials production"                                                           "Critical materials"               0
    "Raw materials production"                                                           "Circularity"                      0
    "Raw materials production"                                                           "Human health"                     0
    "Raw materials production"                                                           "Water usage"                      0
    "Raw materials production"                                                           "Processed gases"                  0
    "Raw materials production"                                                           "Chemical waste"                   0
    "Raw materials production"                                                           "Other"                            0
    "Chip fabrication"                                                                   "Emitted greenhouse gas emissions" 0
    "Chip fabrication"                                                                   "Critical materials"               0
    "Chip fabrication"                                                                   "Circularity"                      0
    "Chip fabrication"                                                                   "Human health"                     0
    "Chip fabrication"                                                                   "Water usage"                      0
    "Chip fabrication"                                                                   "Processed gases"                  0
    "Chip fabrication"                                                                   "Chemical waste"                   0
    "Chip fabrication"                                                                   "Other"                            0
    "Circuit board/Substrate manufacturing (electrical and optical)"                     "Emitted greenhouse gas emissions" 0
    "Circuit board/Substrate manufacturing (electrical and optical)"                     "Critical materials"               0
    "Circuit board/Substrate manufacturing (electrical and optical)"                     "Circularity"                      0
    "Circuit board/Substrate manufacturing (electrical and optical)"                     "Human health"                     0
    "Circuit board/Substrate manufacturing (electrical and optical)"                     "Water usage"                      0
    "Circuit board/Substrate manufacturing (electrical and optical)"                     "Processed gases"                  0
    "Circuit board/Substrate manufacturing (electrical and optical)"                     "Chemical waste"                   0
    "Circuit board/Substrate manufacturing (electrical and optical)"                     "Other"                            0
    "Assembly, packaging, and testing"                                                   "Emitted greenhouse gas emissions" 0
    "Assembly, packaging, and testing"                                                   "Critical materials"               0
    "Assembly, packaging, and testing"                                                   "Circularity"                      0
    "Assembly, packaging, and testing"                                                   "Human health"                     0
    "Assembly, packaging, and testing"                                                   "Water usage"                      0
    "Assembly, packaging, and testing"                                                   "Processed gases"                  0
    "Assembly, packaging, and testing"                                                   "Chemical waste"                   0
    "Assembly, packaging, and testing"                                                   "Other"                            0
    "System integration"                                                                 "Emitted greenhouse gas emissions" 0
    "System integration"                                                                 "Critical materials"               0
    "System integration"                                                                 "Circularity"                      0
    "System integration"                                                                 "Human health"                     0
    "System integration"                                                                 "Water usage"                      0
    "System integration"                                                                 "Processed gases"                  0
    "System integration"                                                                 "Chemical waste"                   0
    "System integration"                                                                 "Other"                            0
    "Manufacturing infrastructure (process engineering, automated design software, ...)" "Emitted greenhouse gas emissions" 0
    "Manufacturing infrastructure (process engineering, automated design software, ...)" "Critical materials"               0
    "Manufacturing infrastructure (process engineering, automated design software, ...)" "Circularity"                      0
    "Manufacturing infrastructure (process engineering, automated design software, ...)" "Human health"                     0
    "Manufacturing infrastructure (process engineering, automated design software, ...)" "Water usage"                      0
    "Manufacturing infrastructure (process engineering, automated design software, ...)" "Processed gases"                  0
    "Manufacturing infrastructure (process engineering, automated design software, ...)" "Chemical waste"                   0
    "Manufacturing infrastructure (process engineering, automated design software, ...)" "Other"                            0
    "Tool supplier (lithography, deposition, placement, ...)"                            "Emitted greenhouse gas emissions" 0
    "Tool supplier (lithography, deposition, placement, ...)"                            "Critical materials"               0
    "Tool supplier (lithography, deposition, placement, ...)"                            "Circularity"                      0
    "Tool supplier (lithography, deposition, placement, ...)"                            "Human health"                     0
    "Tool supplier (lithography, deposition, placement, ...)"                            "Water usage"                      0
    "Tool supplier (lithography, deposition, placement, ...)"                            "Processed gases"                  0
    "Tool supplier (lithography, deposition, placement, ...)"                            "Chemical waste"                   0
    "Tool supplier (lithography, deposition, placement, ...)"                            "Other"                            0
    "EDA design"                                                                         "Emitted greenhouse gas emissions" 0
    "EDA design"                                                                         "Critical materials"               0
    "EDA design"                                                                         "Circularity"                      0
    "EDA design"                                                                         "Human health"                     0
    "EDA design"                                                                         "Water usage"                      0
    "EDA design"                                                                         "Processed gases"                  0
    "EDA design"                                                                         "Chemical waste"                   0
    "EDA design"                                                                         "Other"                            0
    "ASIC functionalization"                                                             "Emitted greenhouse gas emissions" 0
    "ASIC functionalization"                                                             "Critical materials"               0
    "ASIC functionalization"                                                             "Circularity"                      0
    "ASIC functionalization"                                                             "Human health"                     0
    "ASIC functionalization"                                                             "Water usage"                      0
    "ASIC functionalization"                                                             "Processed gases"                  0
    "ASIC functionalization"                                                             "Chemical waste"                   0
    "ASIC functionalization"                                                             "Other"                            0
    "Research"                                                                           "Emitted greenhouse gas emissions" 0
    "Research"                                                                           "Critical materials"               0
    "Research"                                                                           "Circularity"                      0
    "Research"                                                                           "Human health"                     0
    "Research"                                                                           "Water usage"                      0
    "Research"                                                                           "Processed gases"                  0
    "Research"                                                                           "Chemical waste"                   0
    "Research"                                                                           "Other"                            0
    "Other"                                                                              "Emitted greenhouse gas emissions" 0
    "Other"                                                                              "Critical materials"               0
    "Other"                                                                              "Circularity"                      0
    "Other"                                                                              "Human health"                     0
    "Other"                                                                              "Water usage"                      0
    "Other"                                                                              "Processed gases"                  0
    "Other"                                                                              "Chemical waste"                   0
    "Other"                                                                              "Other"                            0
    end



  • #2
    Here is a way using heatplot from SSC. You can work to define the labels better, I just take the first two words below.

    Code:
    ssc install heatplot, replace
    help heatplot
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str107 A str168 B byte Cnum
    "Raw materials production"                                                           "Emitted greenhouse gas emissions" 0
    "Raw materials production"                                                           "Critical materials"               0
    "Raw materials production"                                                           "Circularity"                      0
    "Raw materials production"                                                           "Human health"                     0
    "Raw materials production"                                                           "Water usage"                      0
    "Raw materials production"                                                           "Processed gases"                  0
    "Raw materials production"                                                           "Chemical waste"                   0
    "Raw materials production"                                                           "Other"                            0
    "Chip fabrication"                                                                   "Emitted greenhouse gas emissions" 0
    "Chip fabrication"                                                                   "Critical materials"               0
    "Chip fabrication"                                                                   "Circularity"                      0
    "Chip fabrication"                                                                   "Human health"                     0
    "Chip fabrication"                                                                   "Water usage"                      0
    "Chip fabrication"                                                                   "Processed gases"                  0
    "Chip fabrication"                                                                   "Chemical waste"                   0
    "Chip fabrication"                                                                   "Other"                            0
    "Circuit board/Substrate manufacturing (electrical and optical)"                     "Emitted greenhouse gas emissions" 0
    "Circuit board/Substrate manufacturing (electrical and optical)"                     "Critical materials"               0
    "Circuit board/Substrate manufacturing (electrical and optical)"                     "Circularity"                      0
    "Circuit board/Substrate manufacturing (electrical and optical)"                     "Human health"                     0
    "Circuit board/Substrate manufacturing (electrical and optical)"                     "Water usage"                      0
    "Circuit board/Substrate manufacturing (electrical and optical)"                     "Processed gases"                  0
    "Circuit board/Substrate manufacturing (electrical and optical)"                     "Chemical waste"                   0
    "Circuit board/Substrate manufacturing (electrical and optical)"                     "Other"                            0
    "Assembly, packaging, and testing"                                                   "Emitted greenhouse gas emissions" 0
    "Assembly, packaging, and testing"                                                   "Critical materials"               0
    "Assembly, packaging, and testing"                                                   "Circularity"                      0
    "Assembly, packaging, and testing"                                                   "Human health"                     0
    "Assembly, packaging, and testing"                                                   "Water usage"                      0
    "Assembly, packaging, and testing"                                                   "Processed gases"                  0
    "Assembly, packaging, and testing"                                                   "Chemical waste"                   0
    "Assembly, packaging, and testing"                                                   "Other"                            0
    "System integration"                                                                 "Emitted greenhouse gas emissions" 0
    "System integration"                                                                 "Critical materials"               0
    "System integration"                                                                 "Circularity"                      0
    "System integration"                                                                 "Human health"                     0
    "System integration"                                                                 "Water usage"                      0
    "System integration"                                                                 "Processed gases"                  0
    "System integration"                                                                 "Chemical waste"                   0
    "System integration"                                                                 "Other"                            0
    "Manufacturing infrastructure (process engineering, automated design software, ...)" "Emitted greenhouse gas emissions" 0
    "Manufacturing infrastructure (process engineering, automated design software, ...)" "Critical materials"               0
    "Manufacturing infrastructure (process engineering, automated design software, ...)" "Circularity"                      0
    "Manufacturing infrastructure (process engineering, automated design software, ...)" "Human health"                     0
    "Manufacturing infrastructure (process engineering, automated design software, ...)" "Water usage"                      0
    "Manufacturing infrastructure (process engineering, automated design software, ...)" "Processed gases"                  0
    "Manufacturing infrastructure (process engineering, automated design software, ...)" "Chemical waste"                   0
    "Manufacturing infrastructure (process engineering, automated design software, ...)" "Other"                            0
    "Tool supplier (lithography, deposition, placement, ...)"                            "Emitted greenhouse gas emissions" 0
    "Tool supplier (lithography, deposition, placement, ...)"                            "Critical materials"               0
    "Tool supplier (lithography, deposition, placement, ...)"                            "Circularity"                      0
    "Tool supplier (lithography, deposition, placement, ...)"                            "Human health"                     0
    "Tool supplier (lithography, deposition, placement, ...)"                            "Water usage"                      0
    "Tool supplier (lithography, deposition, placement, ...)"                            "Processed gases"                  0
    "Tool supplier (lithography, deposition, placement, ...)"                            "Chemical waste"                   0
    "Tool supplier (lithography, deposition, placement, ...)"                            "Other"                            0
    "EDA design"                                                                         "Emitted greenhouse gas emissions" 0
    "EDA design"                                                                         "Critical materials"               0
    "EDA design"                                                                         "Circularity"                      0
    "EDA design"                                                                         "Human health"                     0
    "EDA design"                                                                         "Water usage"                      0
    "EDA design"                                                                         "Processed gases"                  0
    "EDA design"                                                                         "Chemical waste"                   0
    "EDA design"                                                                         "Other"                            0
    "ASIC functionalization"                                                             "Emitted greenhouse gas emissions" 0
    "ASIC functionalization"                                                             "Critical materials"               0
    "ASIC functionalization"                                                             "Circularity"                      0
    "ASIC functionalization"                                                             "Human health"                     0
    "ASIC functionalization"                                                             "Water usage"                      0
    "ASIC functionalization"                                                             "Processed gases"                  0
    "ASIC functionalization"                                                             "Chemical waste"                   0
    "ASIC functionalization"                                                             "Other"                            0
    "Research"                                                                           "Emitted greenhouse gas emissions" 0
    "Research"                                                                           "Critical materials"               0
    "Research"                                                                           "Circularity"                      0
    "Research"                                                                           "Human health"                     0
    "Research"                                                                           "Water usage"                      0
    "Research"                                                                           "Processed gases"                  0
    "Research"                                                                           "Chemical waste"                   0
    "Research"                                                                           "Other"                            0
    "Other"                                                                              "Emitted greenhouse gas emissions" 0
    "Other"                                                                              "Critical materials"               0
    "Other"                                                                              "Circularity"                      0
    "Other"                                                                              "Human health"                     0
    "Other"                                                                              "Water usage"                      0
    "Other"                                                                              "Processed gases"                  0
    "Other"                                                                              "Chemical waste"                   0
    "Other"                                                                              "Other"                            0
    end
    
    set seed 07102024
    replace Cnum= runiformint(1, 100)
    gen A_abbreviated= word(A, 1)+ " " + word(A, 2)
    gen B_abbreviated= word(B, 1)+ " " + word(B, 2)
    encode A_, gen(a)
    encode B_, gen(b)
    heatplot Cnum i.a i.b, xlab(, angle(vert) noticks) ylab(,noticks) plotregion(margin(zero)) color(reds)
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	41.6 KB
ID:	1758410

    Comment


    • #3
      Questions for the OP, as Andrew Musau certainly a great job on the information provided:

      As cnum was all 0 in the data example, what are we (you) looking for?

      There should be a better order than alphabetical.

      I am sceptical often that colours can be decoded effectively from plots like these. See tabplot from the Stata Journal for one alternative.
      https://www.statalist.org/forums/for...updated-on-ssc gives some quick examples.

      Sometimes neither that command nor any other can improve on a table.


      Comment

      Working...
      X