Announcement

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

  • Heatplot with grayscale values

    Hi everyone,
    I am trying to create a heatplot for my below dataset:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(step_one step_two) int total_steps float total_steps_percent
    1 1   4  .5012531
    1 2   2 .25062656
    1 3   0         0
    1 4   0         0
    2 1   0         0
    2 2 117 14.661654
    2 3  18  2.255639
    2 4  11  1.378446
    3 1   0         0
    3 2  17 2.1303258
    3 3 244  30.57644
    3 4  16 2.0050125
    4 1   0         0
    4 2   7   .877193
    4 3  14  1.754386
    4 4 348  43.60902
    end
    In short, the data is about how individuals "jump" from one position to another. The number in the boxes represent the percentage of jumps within and between positions. For e.g., From "1" to "1" there are 0.5% transitions.

    I use the following code for the heatplot:
    Code:
    heatplot total_steps_percent i.step_one i.step_two, sizeprop values(format(%9.3f) size(vsmall))  legend(on) aspectratio(1) color(cblind ,gscale  intensity(.7) reverse)  xscale(alt) yscale(reverse) xtitle("") ytitle("")
    I get the following graph.

    Click image for larger version

Name:	for_stata_list.png
Views:	1
Size:	28.1 KB
ID:	1716867

    As you can see the color codes for most of the values is almost the same, especially for those from 0 to 2.4. The graph is not intuitive in the given form.

    Is there any way I can assign a color code for a specific value? Since there are exactly 12 values from low to high ( 0 being the min and 43.609 being the highest), can I code the colors from the lowest number (the lightest color) to the highest number (the darkest color)? I would like to have it in grayscale.

    Would really appreciate any help.

    Thanks in advance,

    J

  • #2
    Hi everyone,
    Bringing my query back again in case many of you may have missed reading it.
    J

    Comment


    • #3
      Hi everyone,
      Bringing my query back again in case many of you may have missed reading it.
      J

      Comment


      • #4
        Hello! No one is working on STATA heatplots?
        Thanks in advance,
        J

        Comment


        • #5
          From the advice here:

          1.1 Bumping

          Bumping, strict sense, is adding a new post to an existing thread with the sole aim of drawing attention to it. Sometimes this is done crudely ("bump", "anyone?"), sometimes politely ("Any advice on this please?"). We suggest that bumping should be done only

          (a) after some time has elapsed (as a rule of thumb, 12 hours at least); within 1 or 2 hours, or a few minutes, will not be welcome.

          (b) once in a given thread

          (c) very politely indeed.

          Any bumping that just mentions urgency, desperation, or your need for an answer is out of order. It's not that we don't sympathise; it's just that such context doesn't make your question more interesting or easier to answer or deserve extra attention.

          Comment


          • #6
            Noted and apologies for the same.
            Thank you for pointing out my mistake. I will make sure not to repeat this mistake.

            J

            Comment


            • #7
              I know very little about this, but there seem to be at least two issues here:
              • you are not using a sequential palette
              • the nature of your data -- most of your numbers are between 0-2.3, and then you have a very few much bigger numbers -- 14.7, 30.6 and 43.7
              Because of this second, I think you're going to struggle to have much separation of colours -- indeed forcing such separation may even mislead the reader.

              That said, consider this

              Code:
              heatplot total_steps_percent i.step_one i.step_two, ///
                   sizeprop values(format(%9.3f) size(vsmall))  legend(on) aspectratio(1) ///
                   color(HCL reds, n(30) reverse gscale power(0.3)) ///
                   xscale(alt) yscale(reverse) xtitle("") ytitle("")
              Playing around with the n() and power() options may give you what you want. This is all a bit klutzy; others in this forum may have far better ideas.

              My code generates the graph below:

              Click image for larger version

Name:	heat.png
Views:	1
Size:	76.1 KB
ID:	1717056

              Comment


              • #8
                Here is some code that probably comes much closer to what you had in mind:

                Code:
                gen total_steps_perc_round = round(total_steps_percent, 0.01)
                levelsof total_steps_perc_round, local(levels)
                heatplot total_steps_percent i.step_one i.step_two, ///
                    cuts(`levels') ///
                    sizeprop values(format(%9.3f) size(vsmall)) legend(off) aspectratio(1) ///
                    color(#ffffff #e8e8e8 #d2d2d2 #bebebe #ababab #999999 #898989 #797979 ///
                            #6b6b6b #5d5d5d #4f4f4f #414141) ///
                    xscale(alt) yscale(reverse) xtitle("") ytitle("")
                which produces:
                Click image for larger version

Name:	heat.png
Views:	1
Size:	47.3 KB
ID:	1717060

                Last edited by Hemanshu Kumar; 13 Jun 2023, 12:03.

                Comment


                • #9
                  Thank you very much for the inputs, Hemanshu. Highly appreciate your answer that helps me get closer to what I want.

                  J

                  Comment

                  Working...
                  X