Announcement

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

  • Gradient colored scatterplot

    Hello everyone,

    I am trying to make a scatter plot using the plottig scheme (or any scheme for that matter) that shows a change in color as we move from lower to higher values. Is there any way I can achieve this?

    For example lower values take the color blue and as we go up the color transitions to red by fading into it.

    Thank you

  • #2
    You could look at https://journals.sagepub.com/doi/pdf...867X0500500412
    and more categories combine it with https://journals.sagepub.com/doi/pdf...867X1801800402
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Dear Fahad,

      You might benefit from Ben Jann's reply on the Stata 17 wishlist, working with his package heatplot
      in response to my wish for Graded marker fill color by the values of a variable (like marker size), also Opacity controlled.

      Best
      http://publicationslist.org/eric.melse

      Comment


      • #4
        Maarten Buis thank you for the links however, mainly due to my lack of skill, I am unable to execute this task. Nonetheless very interesting color palettes and technique by Nick and Ben Jann

        Comment


        • #5
          ericmelse that sounds like a great idea

          Comment


          • #6
            I tried a method and it seemed to have worked

            Code:
              
            generate weight = var_1/1000           //This is just an example form of weight you can choose any other if you like
                
            #delimit ;
            
            heatplot weight var_1 var_2, discrete scatter
            colors(blue red, opacity(60) ipolate(20))
            p(mlc(black))
            legend(off)
            scheme(plotplain)
            
            addplot(lfit var_1 var_2, lcolor("220 0 12") lpattern(dash))
            
            title("Gradient Scatterplot with Line of best fit using Heatplot")
            
            ;
            #delimit cr
            Click image for larger version

Name:	Graph.png
Views:	1
Size:	40.8 KB
ID:	1575665

            Last edited by Fahad Mirza; 05 Oct 2020, 13:02.

            Comment


            • #7
              Thank you for suggesting heatplot, it really made a difference on how my graph looked. will be great if you all can add to this so that I can improve it.

              Comment


              • #8
                I think incorporating the size option would improve the graph.

                Comment


                • #9
                  Justin Blasongame you mean linearly increase size of plots just like how colors are changing?

                  Comment


                  • #10
                    Not quite. I mean to show some scale to the plots. Consider the example below, where the dots reflect the number of jobs -- this doesn't apply to your example, but it's an example I can think of where using this option helps.

                    Code:
                    * Example generated by -dataex-. To install: ssc install dataex
                    clear
                    input double local_emp float(wage lq)
                     84279  160.9143  .6679937
                     55280  42.59007 1.0586338
                     25736 37.093792 1.0633941
                     31394  51.12663  1.533422
                     56712  47.90494  .7758535
                     31578  47.97167 1.0501165
                     73749  42.45197 1.0328938
                     24839  49.11127 1.3231826
                     22602  77.65968  .9109533
                     82682  28.90806 1.0353069
                     10415  154.1099 .56889135
                    125796  95.27658 1.1112541
                    457004 111.85567   .813385
                    149258 25.486544 1.0186863
                     90220  24.87117 1.1197183
                     34243  120.9658  .8878158
                     43233  54.02937  .9697956
                      2836 212.27405  .6684303
                    end
                    
                    
                    heatplot local_emp lq wage , discrete stat(asis) scatter size(local_emp)  ///
                    p(mlc(black)) colors( plasma , opacity(60) ipolate(20))    ///
                    ytitle("LQ", size(small)) ylab(, format(%5.2f)) ///
                    xtitle("Wage (\$000s)", size(small)) xlab(, format(%9.0fc)) ///
                    legend(off)    ///
                    scheme(plotplain)

                    Comment


                    • #11
                      Justin Blasongame this looks good and yes this is making quite more sense plus the fact that now there are 3 information being presented. Thanks again for this.

                      Comment

                      Working...
                      X