banner



How To Change The Background Color In Stata Graph

Groundwork/coordinate system

grstyle set patently

grstyle set plain applies a apparently overall look (white background, no shading of by-labels and matrix labels, black championship, and filigree lines in greyness). Example:

                          . grstyle init              . grstyle set plainly, horizontal grid              . sysuse auto, articulate              (1978 Motorcar Data)              . besprinkle price mpg, by(foreign)                      

Code

grstyle-set/plain.svg

Option grid request that all grid lines be printed. Option horizontal sets the orientation of tick labels on the y axis to horizontal. Moreover, you can use option dotted to request dotted grid lines:

                          . grstyle init              . grstyle set plain, horizontal grid dotted              . sysuse automobile, clear              (1978 Auto Data)              . scatter cost mpg                      

Code

grstyle-set/plain2.svg

Furthermore, choice nogrid turns grid lines off and option noextend requests that axis lines only be fatigued to the smallest and largest tick:

                          . grstyle init              . grstyle set up obviously, nogrid noextend              . sysuse motorcar, articulate              (1978 Auto Data)              . scatter price mpg                      

Code

grstyle-set/plain3.svg

grstyle set mesh

grstyle prepare mesh uses a mesh of grid lines as coordinate plane, omits axis lines and ticks, and prints filigree lines and tick labels in gray. Example:

                          . grstyle init              . grstyle set mesh, horizontal              . sysuse automobile, clear              (1978 Automobile Information)              . scatter price mpg                      

Code

grstyle-set/mesh.svg

Option horizontal sets the orientation of tick labels on the y axis to horizontal. Furthermore, you can use option compact to reduce the symbols size, some font sizes, and the graph margin, and pick modest to add a small grid:

                          . grstyle init              . grstyle set up mesh, horizontal meaty minor              . sysuse auto, clear              (1978 Machine Data)              . scatter price mpg                      

Lawmaking

grstyle-set/mesh2.svg

grstyle set imesh

grstyle set up imesh uses an inverted mesh of grid lines as coordinate plane (greyness background with white grid lines; no centrality lines). Example:

                          . grstyle init              . grstyle set imesh, horizontal                            . sysuse auto, clear              (1978 Auto Information)              . besprinkle cost mpg                      

Code

grstyle-set/imesh.svg

Option horizontal sets the orientation of tick labels on the y axis to horizontal. Furthermore, you can use choice meaty to reduce the symbols size, some font sizes, and the graph margin, and option minor to add a minor grid:

                          . grstyle init              . grstyle set up imesh, horizontal compact minor              . sysuse auto, clear              (1978 Automobile Data)              . scatter price mpg                      

Lawmaking

grstyle-set/imesh2.svg

grstyle set horizontal

grstyle set horizontal sets the orientation of tick labels on the y axis to horizontal:

                          . grstyle init              . grstyle set horizontal              . sysuse auto, clear              (1978 Automobile Data)              . scatter price mpg                      

Code

grstyle-set/hor.svg

grstyle set compact

grstyle fix compact reduces the symbols size, some font sizes, and the graph margin:

                          . grstyle init              . grstyle gear up compact              . sysuse auto, articulate              (1978 Machine Data)              . scatter price mpg                      

Code

grstyle-set/compact.svg

grstyle set filigree

grstyle set grid turns all grid lines on (horizontal, vertical, minimum, maximum):

                          . grstyle init              . grstyle set filigree              . sysuse auto, clear              (1978 Car Data)              . scatter price mpg                      

Code

grstyle-set/grid.svg

grstyle set nogrid

grstyle ready nogrid turns filigree lines off:

                          . grstyle init              . grstyle fix nogrid              . sysuse motorcar, clear              (1978 Car Data)              . scatter price mpg                      

Code

grstyle-set/nogrid.svg

This does not touch on all plot types. For instance, in graphs using the past() option the default horizontal filigree lines are still drawn. Employ option ylabel(, nogrid) to the graph command to omit these grid lines.

grstyle prepare noextend

grstyle gear up noextend causes axis lines to be drawn merely to the smallest and largest tick marks without extending them to the bounding box of the plot region:

                          . grstyle init              . grstyle set noextend              . sysuse motorcar, articulate              (1978 Automobile Data)              . scatter price mpg                      

Code

grstyle-set/noextend.svg

The fable

grstyle set fable determines the position and some way aspects of the legend. Example:

                          . grstyle init              . grstyle ready legend 2, inside              . sysuse auto, clear              (1978 Machine Data)              . two (besprinkle price mpg if foreign) (scatter toll mpg if !foreign)                      

Code

grstyle-set/legend.svg

Option within requests placing the legend inside the plot region. Statement 2 moves the legend to the tiptop right; see help clockposstyle. In the following example, the legend is placed at the lower right side of the plot region and the frame around the fable is removed:

                          . grstyle init              . grstyle gear up imesh, horizontal compact small-scale              . grstyle set up fable 4, nobox              . sysuse auto, clear              (1978 Machine Information)              . two (scatter price mpg if foreign) (scatter cost mpg if !strange)                      

Code

grstyle-set/legend2.svg

Transparent CIs

grstyle gear up ci makes shading of conviction intervals transparent (Stata xv required):

                          . grstyle init              . grstyle set ci              . sysuse auto, clear              (1978 Machine Data)              . two (besprinkle price length)                ///                >     (lpolyci price length if strange==0)                ///                >     (lpolyci price length if strange==1, astyle(ci2))                ///                >     , legend(off)                      

Lawmaking

grstyle-set/ci.svg

By default, gs12 and ltkhaki are used equally colors for ci and ci2 (as in the s2color scheme), and opacity is set to 50%. The post-obit example uses colors 11 and 13 from the burd palette and sets opacity to 60%:

                          . grstyle init              . grstyle set ci burd, select(11 thirteen) opacity(60)              . sysuse automobile, clear              (1978 Motorcar Data)              . ii (scatter price length)                ///                >     (lpolyci toll length if foreign==0)                ///                >     (lpolyci price length if foreign==1, astyle(ci2))                ///                >     , fable(off)                      

Code

grstyle-set/ci2.svg

Colors

Assigning a palette

grstyle set color assigns colors using the color scheme entry attribute. See assistance colorpalette for bachelor color palettes. Here is an example using the economist palette:

                          . grstyle init              . grstyle set fable two, nobox              . grstyle prepare color economist              . sysuse nlsw88, clear              (NLSW, 1988 extract)              . graph bar wage if occ<ix, over(occ) asyvars over(matrimony)                      

Code

grstyle-set/color.svg

Same graph using the rainbow scheme from the ptol palette:

                          . grstyle set color ptol rainbow, north(8) reverse              . graph bar wage if occ<ix, over(occ) asyvars over(union)                      

Code

grstyle-set/color2.svg

Same graph using the Greens palette from ColorBrewer:

                          . grstyle set up colour Greens, n(8)              . graph bar wage if occ<9, over(occ) asyvars over(union)                      

Code

grstyle-set/color3.svg

Option n() has been specified in the last ii examples because these palettes provide different colors depending on the number of colors one requires. The same is true in the following instance that uses HCL colors with evenly spaced hues (hue palette):

                          . grstyle init              . grstyle prepare imesh, horizontal compact small              . grstyle set legend 4, nobox stack              . grstyle linewidth plineplot 0.seven              . grstyle set colour hue, n(4)              . sysuse uslifeexp, clear              (U.Due south. life expectancy, 1900-1999)              . foreach v in le_wfemale le_wmale le_bfemale le_bmale {              2.     label variable `v' `"`=substr("`:var lab `v''",eighteen,.)'"'              3. }              . line le_wfemale le_wmale le_bfemale le_bmale twelvemonth, ytitle(Life expectancy)                      

Code

grstyle-set/color4.svg

Specifying custom colors

Instead of using a named palette you can provide custom colors past specifying a list of colorstyles (named colors, RBG colors specified as "# # #", CMYK colors specified as "# # # #", or HSV colors specified as "hsv # # #"). In add-on, grstyle gear up likewise supports colors specified as hex triplets or in HCL format ("hcl # # #"). See Specifying colors in aid grstyle set up for details. Here is an example using hex codes of semantic colors used for buttons in Bootstrap v3.3:

                          . grstyle init              . grstyle set color #286090 #449d44 #31b0d5 #ec971f #c9302c              . driblet _all              . input principal success info warning danger              master     success        info     warning      danger   i. 12 14 ii 8 5   2. end              . graph pie primary success info warning danger                ///                >     , plabel(_all name, size(*i.5) color(white)) fable(off)                      

Code

grstyle-set/hex.svg

Making markers transparent

Making marker symbols transparent is a flake tricky. If you lot just make their color transparent, the marker outline will look unlike than the marker fill up because the outline is printed on top of the make full. A solution is to make the outline fully transparent, every bit in the following example:

                          . grstyle init              . grstyle fix imesh              . grstyle set color Set1, opacity(50): p#markfill              . grstyle set colour Set1, opacity(0):  p#markline              . grstyle symbolsize p huge              . sysuse auto, clear              (1978 Auto Data)              . 2 (besprinkle price length if foreign) (besprinkle price length if !foreign)                      

Code

grstyle-set/tmark.svg

Colour intensity

Color intensity can be set using the intensity() pick when calling grstyle set color. For some elements, however, color intensity tin also be fix as a split up scheme entry using grstyle prepare intensity. The following example sets the fill intensity of bars in graph bar to thirty percent:

                          . grstyle init              . grstyle set plain              . grstyle set colour Accent: p#bar p#barline                            . grstyle set inten 30: bar              . sysuse citytemp, articulate              (City Temperature Information)              . graph bar (mean) tempjuly tempjan, over(region) bargap(-30)                      

Code

grstyle-set/inten.svg

Symbols and line patterns

Command grstyle fix symbol assigns marker symbols, command grstyle ready lpattern assigns line patterns. Stata'due south default color schemes use filled circles as marker symbols and solid lines for all plots, which makes the graphs hard to read on black and white printouts. To improve readability, you could change the symbols and line patterns as in the following case:

                          . grstyle init              . grstyle set up evidently              . grstyle set color Set1              . grstyle set symbol              . grstyle set up lpattern              . sysuse machine, articulate              (1978 Automobile Data)              . quietly separate toll, by(foreign) shortlabel              . two connect toll? weight, ytitle(Toll) sort                      

Lawmaking

grstyle-set/symbol.svg

Since Stata 15 it is possible to use rotated symbols. Corresponding scheme entries tin be constructed using the anglestyle scheme entry attribute. Instance:

                          . grstyle init              . grstyle set up plain              . grstyle set color Set1, opacity(50)              . grstyle ready symbolsize large              . grstyle set symbol T T              . grstyle anglestyle p2symbol 180              . sysuse auto, articulate              (1978 Machine Data)              . qui carve up price, by(foreign)              . besprinkle price? weight, ytitle(Price)                      

Lawmaking

grstyle-set/angle.svg

Accented sizes

grstyle set provides a number of subcommands to set the size of objects, thickness of lines, and width of margins. Run into grstyle gear up size, grstyle prepare symbolsize, grstyle set linewidth, and grstyle fix margin. Their usage with standard size specifications as documented in textsizestyle , markersizestyle , linewidthstyle , and marginstyle is straightforward. In addition to these relative sizes, however, grstyle set also supports the specification of sizes in accented units (inches, points, centimeters, or millimeters).

The procedure is to kickoff ascertain the desired graph size using grstyle set graphsize. After that, apply grstyle ready size etc. to set sizes in absolute terms. An example is every bit follows:

                          . grstyle init              . grstyle set legend 2              . grstyle set graphsize 10cm 13cm              . grstyle set size 12pt: heading              . grstyle prepare size 10pt: subheading axis_title              . grstyle set size 8pt: tick_label key_label              . grstyle set symbolsize i two iii 4 v, pt              . grstyle prepare linewidth 0: pmark              . grstyle set linewidth 1pt: axisline tick major_grid legend xyline              . grstyle set linewidth 2.5pt: plineplot              . grstyle set margin .5cm: twoway                // margin of plot region                            . grstyle set margin ".5 1 .75 .25", cm: graph                // margin of graph region                            .                // (left right bottom peak)                            . sysuse car, clear              (1978 Auto Information)              . quietly separate price, by(rep) shortlabel              . twoway (scatter price? weight) (lfit price weight),                ///                >     championship("Title (12pt)") subtitle("Subtitle (10pt)")                ///                >     xtitle("Ten axis title (10pt)") ytitle("Y axis title (10pt)")                ///                >     fable(order(1 "1pt" ii "2pt" iii "3pt" 4 "4pt" 5 "5pt"))                ///                >     plotregion(colour(gs14) icolor(white))                ///                >     graphregion(color(gs14) icolor(ltbluishgray))                      

Code

grstyle-set/sizes.svg

The requested accented sizes will only be preserved as long as the graph size (i.e., the minimum of height and width of the graph) does not alter. Also encounter Setting accented sizes in assist grstyle set.

Custom subcommand

A personal collection of graph settings tin can be provided by defining a program chosen grstyle_set_myname . myname will then be available to grstyle set like any other subcommand.

When calling your plan, grstyle set provides global macro GRSTYLE_FH containing the file handle of the scheme file to be written to. Utilize file write with this handle to add your scheme entries. For instance, the following program would prepare the default guess number of labeled ticks to 10 (and print y-labels horizontally):

            capture program drib grstyle_set_10ticks programme grstyle_set_10ticks     file write $GRSTYLE_FH "numticks_g horizontal_major ten" _n     file write $GRSTYLE_FH "numticks_g vertical_major   10" _n     file write $GRSTYLE_FH "anglestyle vertical_tick horizontal" _n end                      

Code

After defining the program (or storing the program in file grstyle_set_10ticks.ado), it can be used as follows:

                          . grstyle init              . grstyle set 10ticks              . sysuse auto, clear              (1978 Machine Data)              . besprinkle toll weight                      

Code

grstyle-set/10ticks-ex.svg

Your program tin can likewise accept options. Here is an extended example with an selection for the approximate number of labeled ticks and an additional option to set the number of unlabeled minor ticks betwixt the labeled ticks:

            capture program driblet grstyle_set_nticks programme grstyle_set_nticks     syntax [, n(int 5) mticks(int 0) ]     file write $GRSTYLE_FH "numticks_g horizontal_major `northward'" _n     file write $GRSTYLE_FH "numticks_g vertical_major   `n'" _n     file write $GRSTYLE_FH "anglestyle vertical_tick horizontal" _n     file write $GRSTYLE_FH "numticks_g horizontal_tminor `mticks'" _n     file write $GRSTYLE_FH "numticks_g vertical_tminor   `mticks'" _n end                      

Lawmaking

Yous could then, for example, type:

                          . grstyle init              . grstyle set nticks, n(10) mticks(v)              . sysuse auto, clear              (1978 Automobile Data)              . scatter toll weight                      

Code

grstyle-set/nticks-ex.svg

How To Change The Background Color In Stata Graph,

Source: http://repec.sowi.unibe.ch/stata/grstyle/grstyle-set.html

Posted by: rosenbergequed1960.blogspot.com

0 Response to "How To Change The Background Color In Stata Graph"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel