Announcement

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

  • Colour in Stata graph does not match same colour in other programs

    I work in a group of people putting together a report. I use primarily Stata to create graphs, a colleague uses R, and the report is created by MS SQL Server Reporting Services (SSRS) and published as PDF files.
    In the report there is a coloured banner heading each page. The banner colour is selected from our institution's defined colour palette, and is specified in the SSRS template using the hex code given below. This is the colour wanted in the graphs.
    My colleague specifies the hex code in R, and gets R graphs that visually match the banner.
    It turns out that if I specify the RGB code for this colour in my Stata graphs, it does not match the colour in the R graphs or the banner. The Stata graph comes out less intense and with a noticeably different hue.
    I am certain that I use the correct translation of codes hex-to-RGB, I have used two separate translator tools and checked the calculation myself. In addition, I have used a colour selector (like the one found in Stata Graph Editor) to manually find a colour which makes the Stata graph look very close to the banner colour, and it turns out to have a very different RGB code in Stata.
    Any explanations, or methods to translate from hex to the correct RGB code needed in Stata?

    My colour example: A dark blue.
    - hex: #393c61 - used in the report banner.
    - This translates to decimal RGB: "57 60 97" , which in a Stata graph is not the same colour visually.
    - In Stata, the code "24 24 71" gives a nearly correct colour.
    Last edited by Steinar Bjørnæs; 10 Feb 2022, 05:51.

  • #2
    I quickly tried to check the colour value using a simple toy plot

    Code:
    twoway scatteri 1 1 , mcol("57 60 97") msize(vhuge)
    Copying that graph into any image editor shows the correct color value for the dot, which makes me think that some kind of colour interpretation is happening in the report building process, but I'm at a loss for how to help further. If you simply compare the Stata graph to the colour example (without merging into a document) do they appear the same?

    Comment


    • #3
      Can you report the graph export command used?

      Comment


      • #4
        Steinar Bjørnæs
        I'm not sure I can detect the same issue that you found. I got the same result for the hexadecimal value as you did:

        Code:
        . hextorgb, hex("393c61")
        ________________________________________________________________________________
                  Red       Green     Blue      RGB               RGB String                 
        ________________________________________________________________________________
        
                  57       60        97        57, 60, 97        "57 60 97"
        But the output that I get when comparing the two colors shows a negligible difference:

        Code:
        brewcbsim "57 60 97" "24 24 71"
        Click image for larger version

Name:	colorCompare.png
Views:	1
Size:	141.4 KB
ID:	1649608

        Comment


        • #5
          - The visible colour in the Stata graph window is the same as in the graph in the finished report (after graph export -> upload to SQL Server -> output by SSRS -> conversion to PDF by SSRS).
          - Graph export command: graph export "File_name.png", width(1200) /*height()*/ replace.
          - In the Color Sight simulator graph, is it the top two squares which are the original colours? At least how it shows here on Statalist, both colours are a little darker than in my Graph window, but still you can see my issue: To the left you see the black border clearly, while to the right the central colour is so dark that the black border is almost indistinguishable from the rest. In other words, the left colour is noticeably lighter, which is also what I get.

          Comment


          • #6
            Are you using Stata for Windows, Mac, or Unix?
            -Chinh Nguyen

            Comment


            • #7
              Stata SE 17.0 for Windows.

              Comment


              • #8
                An extension of my original question is this illustration: Here the same original colour (hex #393c61) is expressed in identical Stata graphs using the three different coding systems accepted by Stata, and the colours in the graph (which should be identical) are completely different.
                The codes were obtained from https://imagecolorpicker.com , a website that can analyze the colour in an uploaded image and gives the codes in many systems. I presented the leftmost figure, copied from our institution's colour palette, and got the correct hex code and the same RGB code I knew to be right. I haven't independently verified the CMYK and HSL codes.

                Click image for larger version

Name:	Stata_graph_colours_compared.PNG
Views:	1
Size:	13.7 KB
ID:	1650170

                Comment


                • #9
                  Originally posted by Steinar Bjørnæs View Post
                  An extension of my original question is this illustration: Here the same original colour (hex #393c61) is expressed in identical Stata graphs using the three different coding systems accepted by Stata, and the colours in the graph (which should be identical) are completely different.
                  The codes were obtained from https://imagecolorpicker.com , a website that can analyze the colour in an uploaded image and gives the codes in many systems. I presented the leftmost figure, copied from our institution's colour palette, and got the correct hex code and the same RGB code I knew to be right. I haven't independently verified the CMYK and HSL codes.

                  [ATTACH=CONFIG]n1650170[/ATTACH]
                  My first observation about your graph is that you've got different outline colors and fill colors. What graph command are you using to generate the bar graph because it looks like it's using a fill intensity of about 75%? I opened up the image in Photoshop and verified the outline color is your requested RGB value of (57, 60, 97). Here's a sample graph that I confirmed outputs the requested color:

                  Code:
                  sysuse citytemp, clear
                  gr bar (mean) tempjan, over(region) bar(1, color(57 60 97))
                  Click image for larger version

Name:	junk.png
Views:	1
Size:	20.1 KB
ID:	1650203
                  -Chinh Nguyen

                  Comment


                  • #10
                    The complete script (only translated some comments into English):


                    * Where to save result
                    global target "F:/Forskningsprosjekter/PDB 2455 - Helseprofiler og til_/PRODUKSJON\PRODUKTER\SSRS_filer/FHP/2022/kommune"
                    cd "$target"
                    *-------------------------------------
                    clear
                    input riskfakt andel
                    0 7
                    1 21
                    2 44
                    3 65
                    4 83
                    end

                    * Value labels for the x-axis
                    label define riskfakt 0 "0" 1 "1" 2 "2" 3 "3" 4 "4+"
                    label values riskfakt riskfakt

                    * Some parametres
                    global ymax = 100
                    local mindrelik = ustrunescape("\u2a7d")
                    local yaksetekst "Andel lite fornøyde (fornøydhet `mindrelik' 5), i prosent"
                    local xaksetekst "Antall risikofaktorer"

                    * Bar colour according to FHIs webpalette
                    *local landsfarge "39 39 114*1.6" //Dark blue, equal to the banner, found by experimenting
                    local landsfarge "24 24 71" //The same colour in proper RGB code.

                    *local kommunefarge "9 117 181" //Intermediate blue

                    *local landsfarge "57 60 97" //Hex code for the banner, #393c61, translated to RGB - BUT
                    //it is less intense and lighter than the banner.

                    *TESTED DIFFERENT CODES FOR THE SAME COLOUR: Translations of hex #393c61 into other systems.
                    *local landsfarge "57 60 97" // RGB, turns out greyer and lighter than wanted
                    *local landsfarge "41 38 0 62" // CMYK, turns out much lighter
                    *local landsfarge "hsl 236 26 30" // HSL, the bars turn out black

                    graph twoway ///
                    (bar andel riskfakt , ///
                    color("`landsfarge'") barwidth(0.6) ///
                    ylabel(0(20)$ymax, angle(horizontal) nogrid) ///
                    ytitle("`yaksetekst'", size(medium) orientation(vertical)) ///
                    yscale(range($ymax )) /// Uten denne får ikke øverste ylabel noen gridline.
                    xlabel(, valuelabel) ///
                    xtitle("`xaksetekst'", size(medium)) ///
                    graphregion(fcolor(white) lcolor(white) ilcolor(white)) ///
                    plotregion(fcolor(white) margin(zero)) ///
                    legend(off) ///
                    ) ///
                    (scatter andel riskfakt, msymbol(none) mlabpos(12) mlabel(andel) mlabcolor(black) mlabsize(*1.2) xscale(range(-0.5, 4.5)))
                    *exit
                    graph export "Andel_lite_fornøyde_etter_riskfakt.png", width(1200) /*height()*/ replace

                    Comment


                    • #11
                      As you can see above, I have not (knowingly) specified different outline and fill colours. Your comment made me wonder, so I looked up what graph scheme I use, and "query graphics" reports my settings like this:
                      Graphics settings
                      set graphics on
                      set autotabgraphs on
                      set scheme s2color
                      set printcolor asis may be automatic, asis, gs1, gs2, gs3
                      set copycolor asis may be automatic, asis, gs1, gs2, gs3

                      I don't know what is hiding inside the "s2color" scheme (as you maybe can see from the graph command; I would not be surprised if it could have been made simpler by selecting another scheme ...)

                      Comment


                      • #12
                        The default fill intensity for the bar style is inten80 (80%). You need to specify the option for setting the fill intensity to fintensity(full). See help barlook_options for more information.
                        -Chinh Nguyen

                        Comment


                        • #13
                          Aha, thank you! I would never have discovered that one by myself.

                          I would like to understand for what graph types this "80 %" setting will take effect.
                          I tried to read the scheme file (s2color), where I found (among others) these settings:
                          intensity full
                          intensity bar full
                          intensity bar_line full
                          intensity p inten80
                          To me, it looked like "bar" has full intensity. I thought, then "twoway bar" must be regarded as a graph type with "plots" as in "intensity p"? But in "help barlook_options" it is stated that "The barlook_options determine the look of bars produced by graph bar, graph hbar, graph twoway bar, and several other commands that render bars." Is the underlying grouping of graph types in the scheme file different from that of the barlook_options? Is there any other way to learn where this "80 %" setting will take effect?

                          Comment

                          Working...
                          X