Announcement

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

  • Graph and custom colors (colorpalette)

    Hi everyone!

    I'm currently trying to customize a graph (binscatter) with specific colors, however Stata doesn't recognize them(?) because the graph shows everything in black (which isn't either of the colors I'm trying to use). I'm following this guide: https://medium.com/the-stata-guide/s...s-4320b16f7ef7
    and I'm pretty sure all the packages needed are installed.

    Code:
    colorpalette SlateBlue LightSeaGreen SandyBrown w3-lime w3-deep-orange, nograph
    return list
    binscatter z_math asistencia_6b, by(year) mcolor("`r(p1)'" "`r(p2)'" "`r(p3)'" "`r(p4)'") lcolor("`r(p1)'" "`r(p2)'" "`r(p3)'" "`r(p4)'")
    Using the rgb codes generates the same results.

    This is the "error":
    (note: named style ... not found in class color, default attributes used)

    Thanks in advance!
    Click image for larger version

Name:	Captura de Pantalla 2022-11-15 a la(s) 00.56.10.png
Views:	1
Size:	260.9 KB
ID:	1689442

    Click image for larger version

Name:	Graph_.png
Views:	1
Size:	48.3 KB
ID:	1689443

    Last edited by Mau Aburto; 14 Nov 2022, 21:14.

  • #2
    I'm getting pretty much the same error. I've browsed through a lot of forums and no one seems to know how to fix it

    Comment


    • #3
      I cannot reproduce your problem. Could you include a data extract using the dataex command, and show us the code and the graph you get using that data extract?

      Comment


      • #4
        Originally posted by Hemanshu Kumar View Post
        I cannot reproduce your problem. Could you include a data extract using the dataex command, and show us the code and the graph you get using that data extract?
        Thanks for the help! Here's the data extract (I can produce the graph with the default stata colors btw, it's just that I'm also working with other softwares and the graphs need to be consistent with each other and in specific colors):

        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input float(year z_math asistencia_6b)
        2015     -.9246545 .9894737
        2016      .6718008 .9255319
        2016    -.22197075 .9005525
        2015     .07995805  .968421
        2015      .5823442 .9521276
        2018     -.8060123 .8932585
        2018    -1.0256857        1
        2018    -1.7418988 .9572192
        2018      .7430748 .9189189
        2018      .8597357        1
        2016    -.08347882 .6158192
        2015 -.00051853375  .972973
        2016      .4167096      .95
        2017      .2391258 .8956044
        2015     1.4126695 .9005235
        2015      .4701208 .8505155
        2017      .2705826 .8681319
        2017      .0732486  .983871
        2016     1.1788111 .9230769
        2018     -.7666921 .9672131
        2018    -.06737691 .8715084
        2016     1.2703456 .9712644
        2018    -.27388936 .9234973
        2015   -.014963173        1
        2015     -.6052863 .9333333
        2015      .7625042 .9623656
        2015    -2.6814966 .9444444
        2016    -.05016455  .920904
        2015      1.822832 .9946808
        2017     -.9096935        1
        2017     1.4693435        1
        2017    -1.7314603 .9719101
        2015      .7675838 .9261364
        2016     -.8957102 .9405406
        2015      -.612588 .9417989
        2015      1.447273  .989011
        2018    -.24659267 .9944751
        2016      .7858622 .9887006
        2016      .6159601 .9497207
        2016     .28139067 .9651163
        2016    -.19690578 .9401197
        2015     -.9459246 .9234973
        2016     -1.230438 .9602273
        2016       .461763 .9505494
        2016      .9976452 .9574468
        2018     1.4479144 .9220779
        2017     -.5472926 .8379889
        2018    -1.0040758 .9456522
        2018     .56385905 .9944134
        2015     -.5779844 .9234973
        2015    -1.6668837 .9488636
        2017     -.3635787 .9714286
        2017    -.57258767 .9248555
        2015    -2.3289535        1
        2016    -.02272033 .9304813
        2018     -.8039001 .8603352
        2016      .3978316 .9891892
        2016      .6641864 .9462366
        2016    .010276836 .9402174
        2018      -.907075 .9166667
        end
        label values year year_lbl
        label def year_lbl 2015 "2015", modify
        label def year_lbl 2016 "2016", modify
        label def year_lbl 2017 "2017", modify
        label def year_lbl 2018 "2018", modify

        Comment


        • #5
          This is what I get by running the code on the data extract.
          Click image for larger version

Name:	Captura de Pantalla 2022-11-15 a la(s) 16.31.44.png
Views:	1
Size:	244.1 KB
ID:	1689578

          Click image for larger version

Name:	dataex_graph.png
Views:	1
Size:	37.1 KB
ID:	1689577

          Last edited by Mau Aburto; 15 Nov 2022, 12:38.

          Comment


          • #6
            Okay yes, I can reproduce your problem and I have a temporary workaround for you.

            I am attaching an ado-file called binscatter2.ado. I have merely taken the original ado file (version 7.02, dated 24nov2013) and made the following small modifications:
            • in the syntax command, on line 21, I have added asis to the string options COLors , MColors , LColor and Msymbols
            • I have changed the program name to binscatter2
            Once you put this ado file into an appropriate folder (enter sysdir in Stata, and then put this file into the PERSONAL folder), you should be able to make the following code work:
            Code:
            colorpalette SlateBlue LightSeaGreen SandyBrown w3-lime w3-deep-orange, nograph
            return list
            binscatter2 z_math asistencia_6b, by(year) mcolor(`""`r(p1)'""' `""`r(p2)'""' `""`r(p3)'""' `""`r(p4)'""') lcolor(`""`r(p1)'""' `""`r(p2)'""' `""`r(p3)'""' `""`r(p4)'""') scheme(cleanplots)
            which produces:

            Click image for larger version

Name:	Screenshot 2022-11-16 at 1.44.33 AM.png
Views:	1
Size:	708.6 KB
ID:	1689583
            binscatter2.ado

            Comment


            • #7
              Originally posted by Hemanshu Kumar View Post
              Okay yes, I can reproduce your problem and I have a temporary workaround for you.

              I am attaching an ado-file called binscatter2.ado. I have merely taken the original ado file (version 7.02, dated 24nov2013) and made the following small modifications:
              • in the syntax command, on line 21, I have added asis to the string options COLors , MColors , LColor and Msymbols
              • I have changed the program name to binscatter2
              Once you put this ado file into an appropriate folder (enter sysdir in Stata, and then put this file into the PERSONAL folder), you should be able to make the following code work:
              Code:
              colorpalette SlateBlue LightSeaGreen SandyBrown w3-lime w3-deep-orange, nograph
              return list
              binscatter2 z_math asistencia_6b, by(year) mcolor(`""`r(p1)'""' `""`r(p2)'""' `""`r(p3)'""' `""`r(p4)'""') lcolor(`""`r(p1)'""' `""`r(p2)'""' `""`r(p3)'""' `""`r(p4)'""') scheme(cleanplots)
              which produces:

              [ATTACH=CONFIG]n1689583[/ATTACH] [ATTACH]n1689584[/ATTACH]
              Thank you so much for the help, I really appreciate it, it worked perfectly!

              Comment


              • #8
                Flagging the original author of binscatter, Michael Stepner

                Comment

                Working...
                X