Announcement

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

  • How to adjust graph's transparency?

    Hello,

    I tried to draw a graph like this:

    Click image for larger version

Name:	graph one.jpg
Views:	1
Size:	83.4 KB
ID:	1366694



    but a curve will be covered by another:
    Click image for larger version

Name:	graph two.png
Views:	1
Size:	7.4 KB
ID:	1366695


    Code:
    Code:
    clear
    set obs 100
    
    generate x1 = rnormal(0,1)
    generate x2 = rnormal(0.5,1.3)
    
    summarize x1
    local M1 = r(mean)
    local SD1 = r(sd)
    
    summarize x2
    local M2 = r(mean)
    local SD2 = r(sd)
    
    twoway function x1 = normalden(x, `M1', `SD1') ,recast(area)  range(-4 4) lcolor(black) fcolor(blue*0.04)  || ///
    function x2 = normalden(x, `M2', `SD2'), recast(area) range(-4 5) lcolor(black) fcolor(red*0.03)



    When filled color, the graph below will be covered by the graph above. But I want to make the line of the graph at the bottom show and the overlapped area be marked. Can the transparency of the graph be adjusted or are there any other methods?

    I have installed the "drarea" command which helps to highlight the overlapped area of two graphs and am still working on applying it in making normal distribution plots.

    I'd appreciate any help or suggestion. Thank you!

  • #2
    I am fairly certain there is no way to do this currently in Stata; when I needed it I used -Rsource- (SSC) and then ggplot2 for the overlay.
    __________________________________________________ __
    Assistant Professor, Department of Biostatistics and Epidemiology
    School of Public Health and Health Sciences
    University of Massachusetts- Amherst

    Comment


    • #3
      Lover,
      Thanks for your reply. Then I won't spend much time on STATA's area graphing options and try with R.
      Thanks!

      Comment


      • #4
        The immediate answer is, as Andrew says, that transparency is not supported at present in Stata [NB spelling].

        I'll add that the code in #1 is confused. If you want to plot two normal density functions the random number generation before is quite unnecessary. If you know the means and SDs, you don't need to estimate them either.

        It can be a single graph command (although it can take some experimentation to work out the details).

        Code:
        twoway function normalden(x, 0, 1), ra(-4 4) lc(blue) xli(0, lc(blue)) ///
        || function normalden(x, 0.1, 1.3), ra(-4 4) lc(orange) xli(0.1, lc(orange)) ///
        legend(order(1 "{&mu} = 0, {&sigma} = 1" 2 "{&mu} = 0.1, {&sigma} = 1.3")  pos(11) ring(0) col(1)) ///
        yla(0 "0" 0.1(0.1)0.4, format(%02.1f) ang(h)) ytitle(density) xtitle(value) xla(-4/4)

        Click image for larger version

Name:	normalden.png
Views:	1
Size:	14.0 KB
ID:	1366757

        Comment


        • #5
          Nick,
          Thanks for pointing out the confusion in logic of the code in #1, which indicates that I'm not familiar enough with graphing and normal plot.
          The command is cool!
          In addition, hope that the problem of transparency in STATA will be solved some day.

          Thanks!

          Comment


          • #6
            Transparency is a frequent request at users' meetings. I too would like to see it implemented.

            Comment


            • #7
              Graph color transparency is now available in Stata 15, here is an example:

              Code:
              clear
              set obs 100
              
              generate x1 = rnormal(0,1)
              generate x2 = rnormal(0.5,1.3)
              
              summarize x1
              local M1 = r(mean)
              local SD1 = r(sd)
              
              summarize x2
              local M2 = r(mean)
              local SD2 = r(sd)
              
              twoway ///
                  function x1 = normalden(x, `M1', `SD1'), recast(area)  range(-4 4) lcolor(black) fcolor(blue%25) || ///
                  function x2 = normalden(x, `M2', `SD2'), recast(area) range(-4 5) lcolor(black) fcolor(red%25)
              Click image for larger version

Name:	image_8066.png
Views:	1
Size:	27.6 KB
ID:	1397956

              Comment


              • #8
                Thank you Raciborski,
                I haven't been here for a long time and that's really a surprise!

                Comment


                • #9
                  Dear Rafal Raciborski (StataCorp), how would one apply your code to a histogram?

                  Comment

                  Working...
                  X