Announcement

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

  • coefplot line color

    Hi
    I was wondering how I can change the color of a graph line generated by coefplot. here is my code:
    Code:
    coefplot , drop(_cons) vertical baselevels ///
    ci(95) ciopts(recast(rcap) alcolor(%60)) recast(connected) ///
    ylabel(#9, grid) ytitle("Percentage, %") ///
    And I get the attached graph. the color of the line is blue. I want to change it to other colors. I'd appreciate your insights on that.

    Thanks,
    Click image for larger version

Name:	Graph.jpg
Views:	1
Size:	66.1 KB
ID:	1714286

  • #2
    coefplot is from SSC, as you are asked to explain (FAQ Advice #12).


    Code:
    lcolor(whatever)
    ?

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      coefplot is from SSC, as you are asked to explain (FAQ Advice #12).


      Code:
      lcolor(whatever)
      ?
      when I add the lcolor(black) command I get this graph:

      Comment


      • #4
        help coefplot##plotopts suggests that lcolor (and lpattern) are not options to -coefplot- (from SSC, by Ben Jann Ben Jann) . My experiments to date, based on the auto data set, and the -coefplot- webpages as well as the original SJ article, suggest this as well. I'd be pleased to be shown I am wrong!

        Comment


        • #5
          Originally posted by Stephen Jenkins View Post
          help coefplot##plotopts suggests that lcolor (and lpattern) are not options to -coefplot- ... I'd be pleased to be shown I am wrong!
          With -recast()-, you are calling a twoway plot type. As such, twoway options such as -lcolor()- and -lpattern()- are allowed. An example:

          Code:
          sysuse auto
          regress mpg i.rep78
          set scheme s1mono
          coefplot, recast(connected) lp(dash) lc(blue) drop(_cons)
          Click image for larger version

Name:	Graph.png
Views:	1
Size:	38.7 KB
ID:	1714405

          Last edited by Andrew Musau; 21 May 2023, 14:05.

          Comment


          • #6
            Originally posted by Andrew Musau View Post

            With -recast()-, you are calling a twoway plot type. As such, twoway options such as -lcolor()- and -lpattern()- are allowed. An example:

            Code:
            sysuse auto
            regress mpg i.rep78
            set scheme s1mono
            coefplot, recast(connected) lp(dash) lc(blue) drop(_cons)
            [ATTACH=CONFIG]n1714405[/ATTACH]
            Got you. Thanks for clarigying that. But still with that being notified, I'm not able to change the color of lines in the coefplot when I'm trying to plot multiple models. take this example:

            Code:
             
             coefplot model_1 model_2 model_3 , drop(_cons) vertical baselevels /// ci(95) ciopts(recast(rcap) alcolor(%60)) recast(connected) /// ylabel(#9, grid) ytitle("Percentage, %")
            in this code, how can I change the color for each line separately?

            Comment


            • #7
              just as an extra request, want to label each line on the line not in the legend in the coefplot. something like this

              Click image for larger version

Name:	image_8932.png
Views:	1
Size:	48.7 KB
ID:	1714409


              Is there a way to do this?

              Comment


              • #8
                You are just showing code. Provide a reproducible example (see FAQ Advice #12 for details on how to do this).

                Comment


                • #9
                  Originally posted by Andrew Musau View Post
                  You are just showing code. Provide a reproducible example (see FAQ Advice #12 for details on how to do this).
                  Code:
                  sysuse bpwide, clear
                  estimates clear
                  regress bp_after i.agegrp if sex==0
                  estimates store model_1
                  regress bp_after i.agegrp if sex==1
                  estimates store model_2
                  coefplot model_1 model_2, recast(connected) drop(_cons)
                  this will generate the following graph. i want to set other colors for each line (preferably via the hex code).
                  Click image for larger version

Name:	11.jpg
Views:	1
Size:	23.1 KB
ID:	1714414

                  Last edited by Sa Fe; 21 May 2023, 18:17.

                  Comment


                  • #10
                    thanks, Andrew. Apologies if I wasn't clear. What I meant to say is that I cannot change the colour or pattern of each CI 'bar'. Look at the following:

                    Code:
                    sysuse auto, clear
                     
                    regress price mpg trunk length turn if foreign==0
                    estimates store A
                    regress price mpg trunk length turn if foreign==1
                    estimates store B
                    coefplot (A, label(Domestic Cars) pstyle(p3) msym(oh) ) ///
                         (B, label(Foreign Cars) pstyle(p4)  msym(sh))   ///
                         , drop(_cons) xline(0)
                    So, I can change the marker symbols that represent each of the estimates. However the other details of the point and CI bar appear to be controllable only using pstyle calls (as in Ben's documentation). What I can't see how to do is change the colours (or bar's line pattern) in any other way

                    Comment


                    • #11
                      Originally posted by Stephen Jenkins View Post
                      What I can't see how to do is change the colours (or bar's line pattern) in any other way
                      You do this within -ciopts()-

                      Code:
                      sysuse auto, clear
                       
                      regress price mpg trunk length turn if foreign==0
                      estimates store A
                      regress price mpg trunk length turn if foreign==1
                      estimates store B
                      coefplot (A, label(Domestic Cars) pstyle(p3) ciopts(bcolor(blue)) msym(oh) ) ///
                           (B, label(Foreign Cars) pstyle(p4)  ciopts(bcolor(red)) msym(sh))   ///
                           , drop(_cons) xline(0)
                      Click image for larger version

Name:	Graph.png
Views:	1
Size:	22.8 KB
ID:	1714451

                      Comment


                      • #12
                        Originally posted by Saber Feizy View Post
                        this will generate the following graph. i want to set other colors for each line (preferably via the hex code).
                        Code:
                        sysuse bpwide, clear
                        estimates clear
                        regress bp_after i.agegrp if sex==0
                        estimates store model_1
                        regress bp_after i.agegrp if sex==1
                        estimates store model_2
                        set scheme s1mono
                        coefplot (model_1, recast(connected) lc(red)) (model_2, recast(connected) lc(blue)), drop(_cons)
                        Click image for larger version

Name:	Graph.png
Views:	1
Size:	18.5 KB
ID:	1714453

                        Comment


                        • #13
                          Andrew: you're a champ! Many thanks. (Obvious now -- in hindsight) I can confirm that lpattern works inside ciopts() too

                          Comment


                          • #14
                            [QUOTE=Andrew Musau;n1714452]

                            thank you very much. It worked.

                            Comment

                            Working...
                            X