Announcement

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

  • How can I change the overall background color of a twoway graph?

    Dear Stata-community!

    My question is, how can I change the background color of the overall region of a twoway graph? I have a twoway graph which combines a bar and a line graph, furthermore the graphs are plotted for four different income groups. I changed already the plotregion and the graphregion but I have still the light-blue color in the background. I could do this in the graph editor, however, I would like to plot more graphs for different types in a loop and to change each graph in the graph editor is to much work. I think there must be an easier way. I use Stata15. Here is my code:

    foreach i of numlist 1/15 {
    local label : label(type) `i'
    graph twoway (bar No_natural_disasters year if type == `i', ///
    sort(year) yaxis(1) fi(inten20)) ///
    (line Taff_y_type_GNIG_natdis year if type == `i', ///
    sort(year) yaxis(2)) ///
    , by(GNIG_cat, ///
    title("`label'")) ///
    ylabel(,angle(0) axis(2) nogrid) ///
    ylabel(,angle(0) axis(1) nogrid ) ///
    plotregion( fcolor(white)) ///
    graphregion( fcolor(blue)) ///
    xlabel(,angle(30)) ///
    name(graph_15_`i', replace) ///
    legend(label ( 1 "Number natural disasters" ) label (2 "Affected people per natural disaster"))

    }

    Thanks!
    Attached Files
    Last edited by Markus Simbuerger; 25 Jul 2018, 01:01.

  • #2
    The graphregion() option should be a suboption of the by() option. Compare these two commands:

    Code:
    sysuse auto, clear
    set scheme s2color
    
    scatter weight price, by(foreign) graphregion(fcolor(white)) name(wrong)
    scatter weight price, by(foreign,  graphregion(fcolor(white))) name(right)
    Alternatively, you can start with a different scheme, like s1mono. I still like the user written lean1 scheme (to find it type in stata search lean1)
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thank you very much, it perfectly works!

      Comment


      • #4
        Thank you Buis!

        Comment

        Working...
        X