Docsity

Stata Axis Scale Options: Determining Axis Appearance, Range, and Look, Schemes and Mind Maps of Advanced Computer Programming

Toggle sidebar
bg1
Title stata.com
axis scale options — Options for specifying axis scale, range, and look
Description Quick start Syntax Options Remarks and examples
References Also see
Description
The axis scale options determine how axes are scaled (arithmetic, log, reversed), the range of the
axes, and the look of the lines that are the axes.
Quick start
Put the yaxis on a log scale
graph_command . . . ,. . . yscale(log)
Reverse the order of the ticks and labels on the xaxis
graph_command . . . ,. . . xscale(reverse)
Make the width of the line for the xaxis thick
graph_command . . . ,. . . xscale(lwidth(thick))
As above, but specify line width as 18 point
graph_command . . . ,. . . xscale(lwidth(18pt))
Turn off the xaxis
graph_command . . . ,. . . xscale(off)
1
pf3
pf4
pf5
pf8

Partial preview of the text

Download Stata Axis Scale Options: Determining Axis Appearance, Range, and Look and more Schemes and Mind Maps Advanced Computer Programming in PDF only on Docsity!

Title stata.com

axis scale options — Options for specifying axis scale, range, and look

Description Quick start Syntax Options Remarks and examples References Also see

Description

The axis scale options determine how axes are scaled (arithmetic, log, reversed), the range of the axes, and the look of the lines that are the axes.

Quick start

Put the y axis on a log scale graph_command... ,... yscale(log)

Reverse the order of the ticks and labels on the x axis graph_command... ,... xscale(reverse)

Make the width of the line for the x axis thick graph_command... ,... xscale(lwidth(thick))

As above, but specify line width as 18 point graph_command... ,... xscale(lwidth(18pt))

Turn off the x axis graph_command... ,... xscale(off)

1

Syntax

axis scale options are a subset of axis options; see [G-3] axis options.

axis scale options Description

yscale(axis suboptions) how y axis looks xscale(axis suboptions) how x axis looks tscale(axis suboptions) how t (time) axis looks zscale(axis suboptions) how contour legend axis looks

The above options are merged-implicit; see [G-4] Concept: repeated options.

axis suboptions Description

axis(#) which axis to modify; 1 ≤ # ≤ 9 [ no

]

log use logarithmic scale [ no

]

reverse reverse scale to run from max to min range(numlist) expand range of axis range(datelist) expand range of t axis (tscale() only)

off and on suppress/force display of axis fill allocate space for axis even if off alt move axis from left to right or from top to bottom

fextend extend axis line through plot region and plot region’s margin extend extend axis line through plot region noextend do not extend axis line at all noline do not draw axis line line force drawing of axis line

titlegap(size) margin between axis title and tick labels outergap(size) margin outside axis title

lstyle(linestyle) overall style of axis line lcolor(colorstyle) color and opacity of axis line lwidth(linewidthstyle) thickness of axis line lpattern(linepatternstyle) axis pattern (solid, dashed, etc.)

Options

yscale(axis suboptions), xscale(axis suboptions), and tscale(axis suboptions) specify the look of the y, x, and t axes. The t axis is an extension of the x axis. Inside the parentheses, you specify axis suboptions. zscale(axis suboptions); see Contour axes—zscale() below.

Remarks and examples stata.com

axis scale options are a subset of axis options; see [G-3] axis options for an overview. The other appearance options are

axis label options (see [G-3] axis label options) axis title options (see [G-3] axis title options)

Remarks are presented under the following headings: Use of the yscale( ) and xscale( ) Specifying the range of a scale Obtaining log scales Obtaining reversed scales Suppressing the axes Contour axes—zscale()

Use of the yscale( ) and xscale( )

yscale() and xscale() specify the look of the y and x axes. Inside the parentheses, you specify axis suboptions, for example:

. twoway (scatter... )... , yscale(range(0 10) titlegap(1))

yscale() and xscale() may be abbreviated ysc() and xsc(), suboption range() may be abbreviated r(), and titlegap() may be abbreviated titleg():

. twoway (scatter... )... , ysc(r(0 10) titleg(1))

Multiple yscale() and xscale() options may be specified on the same command, and their results will be combined. Thus the above command could also be specified

. twoway (scatter... )... , ysc(r(0 10)) ysc(titleg(1))

Suboptions may also be specified more than once, either within one yscale() or xscale() option, or across multiple options, and the rightmost suboption will take effect. In the following command, titlegap() will be 2, and range() 0 and 10:

. twoway (scatter... )... , ysc(r(0 10)) ysc(titleg(1)) ysc(titleg(2))

Specifying the range of a scale

To specify the range of a scale, specify the

y | x

scale(range(numlist)) option. This option specifies that the axis be expanded to include the numbers specified. Consider the graph

. scatter yvar xvar

Assume that it resulted in a graph where the y axis varied over 1–100 and assume that, given the nature of the y variable, it would be more natural if the range of the axis were expanded to go from 0 to 100. You could type

. scatter yvar xvar, ysc(r(0))

Similarly, if the range without the yscale(range()) option went from 1 to 99 and you wanted it to go from 0 to 100, you could type

. scatter yvar xvar, ysc(r(0 100))

If the range without yscale(range()) went from 0 to 99 and you wanted it to go from 0 to 100, you could type

. scatter yvar xvar, ysc(r(100))

Specifying missing for a value leaves the current minimum or maximum unchanged; specifying a nonmissing value changes the range, but only if the specified value is outside the value that would otherwise have been chosen. range() never narrows the scale of an axis or causes data to be omitted from the plot. If you wanted to graph yvar versus xvar for the subset of xvar values between 10 and 50, typing

. scatter yvar xvar, xsc(r(10 50))

would not suffice. You need to type

. scatter yvar xvar if xvar >=10 & xvar <=

Obtaining log scales

To obtain log scales specify the

y | x

scale(log) option. Ordinarily when you draw a graph, you obtain arithmetic scales:

. use https://www.stata-press.com/data/r17/lifeexp, clear (Life expectancy, 1998) . scatter lexp gnppc

55

60

65

70

75

80

Life expectancy at birth

0 10000 20000 30000 40000 GNP per capita

Suppressing the axes

There are two ways to suppress the axes. The first is to turn them off completely, which means that the axis line is suppressed, along with all of its ticking, labeling, and titling. The second is to simply suppress the axis line while leaving the ticking, labeling, and titling in place. The first is done by

y | x

scale(off) and the second by

y | x

scale(noline). Also, you will probably need to specify the plotregion(style(none)) option; see [G-3] region options. The axes and the border around the plot region are right on top of each other. Specifying plotregion(style(none)) will do away with the border and reveal the axes to us:

. use https://www.stata-press.com/data/r17/auto, clear (1978 automobile data) . scatter mpg weight, plotregion(style(none))

10

20

30

40

Mileage (mpg)

2,000 3,000 4,000 5, Weight (lbs.)

To eliminate the axes, type

. scatter mpg weight, plotregion(style(none)) yscale(off) xscale(off)

To eliminate the lines that are the axes while leaving in place the labeling, ticking, and titling, type

. scatter mpg weight, plotregion(style(none)) yscale(noline) xscale(noline)

10

20

30

40

Mileage (mpg)

2,000 3,000 4,000 5, Weight (lbs.)

Rather than using

y | x

scale(noline), you may specify

y | x

scale(lstyle(noline)) or

y | x

scale(lstyle(none)). They all mean the same thing.

Contour axes—zscale()

The zscale() option is unusual in that it applies not to axes on the plot region, but to the axis that shows the scale of a contour legend. It has effect only when the graph includes a twoway contour plot; see [G-2] graph twoway contour. In all other respects, it acts like xscale(), yscale(), and tscale().

References

Cox, N. J. 2008. Stata tip 59: Plotting on any transformed scale. Stata Journal 8: 142–145.

. 2012. Speaking Stata: Transforming the time axis. Stata Journal 12: 332–341. . 2018. Speaking Stata: Logarithmic binning and labeling. Stata Journal 18: 262–286.

Also see

[G-3] axis options — Options for specifying numeric axes [G-3] axis label options — Options for specifying axis labels [G-3] axis title options — Options for specifying axis titles [G-3] region options — Options for shading and outlining regions and controlling graph size [TS] tsline — Time-series line plots