Announcement

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

  • Changing bgcolor in coefplot

    Is there a way to change the background color to white when creating plots using coefplot?

    I know the standard way to change background color is bgcolor -- or more completely graphregion(color(white)) bgcolor(white) -- but that option doesn't seem to be available in coefplot, and I can't find any references online or in the forum to changing the background color of plots created using coefplot. Thanks!

  • #2
    Welcome to Statalist.

    My reading of the help coefplot output suggested that the options are indeed available. The implication is that options not recognized by coefplot will be "passed through" to the included plotting commands. So - since you provided the plot options you thought would work, thank you for that, it always takes me forever to find the options I need - I gave it a try with the examples from the help coefplot output.
    Code:
    graph drop _all
    sysuse auto, clear
    
    regress price mpg headroom trunk length turn
    coefplot, drop(_cons) xline(0) graphregion(color(white)) bgcolor(white) name(g1)
    
    regress price mpg headroom trunk length turn if foreign==0
    estimates store domestic
    regress price mpg headroom trunk length turn if foreign==1
    estimates store foreign
    
    coefplot domestic foreign, drop(_cons) xline(0) graphregion(color(white)) bgcolor(white) name(g2)
    
    coefplot domestic || foreign, drop(_cons) xline(0) graphregion(color(white)) bgcolor(white) name(g3)
    
    coefplot domestic || foreign, yline(0) bycoefs vertical byopts(yrescale)  graphregion(color(white)) bgcolor(white) name(g4)
    Copy this into your do-file editor and run it. There is good news and bad news. The results were as I hoped for g1 and g2. For g3 and g4, though, the graph combine that is obviously used to produce the array of plots does not seem to notice the options.

    Or, possibly, the options need to be placed differently, although I admit the section of the help titled "Placement of options" did not reveal to me the problem with my naive code.

    But for me this would all now be trial and error. Perhaps the first two examples suffice for you. If not, perhaps you can alter the second two examples to produce success. (If so, please report back here!) And then, you should have what you need for your actual application.

    Good luck.

    Added in edit - the author's original Stata Journal article is available for free download at https://www.stata-journal.com/articl...article=gr0059 and perhaps among the extensive writeup there will be found some relevant examples.
    Last edited by William Lisowski; 24 Jun 2018, 19:27.

    Comment


    • #3
      Hey, I noticed this on coefplot (SSC) when I first installed it and I have a vague memory of adding these options myself. However, looking at the ado file here, it looks like coefplot ships with standard twoway options (which includes bgcol()). I'm not sure whether it always did or if this is an update (the most recent version is from September 2017). You could possibly be running an old version of coefplot. Try running this code:

      Code:
      ssc install coefplot, replace
      sysuse auto
      regress price mpg headroom trunk length turn
      coefplot, drop(_cons) xline(0) graphregion(col(white)) bgcol(white)
      And see if that doesn't fix your problem. If it doesn't, show me the graph that's produced and I may be able to offer better guidance.
      Last edited by Chris Larkin; 24 Jun 2018, 19:31. Reason: Crossed with #2

      Comment


      • #4
        Thank you so much for the quick responses! I followed your instructions, and these work now. (Sorry - I didn't have to troubleshoot, so I don't have insights on g3 and g4, William.)

        Comment


        • #5
          Another option would be to manipulate the graph options using "grstyle" or just using a graph scheme that sets the background color to white. E.g.:

          Code:
          *** using a suitable graph scheme
          ssc install scheme_tufte ,replace
          set scheme tufte
          coefplot ...
          
          *** with grstyle
          ssc install grstyle
          scheme s2color
          grstyle init
          grstyle color background white // set overall background to white
          grstyle set color black*.04: plotregion color //set plot area background
          coefplot ...

          Comment

          Working...
          X