help twoway rarea dialog: twoway
-------------------------------------------------------------------------------
Title
[G] graph twoway rarea -- Range plot with area shading
Syntax
twoway rarea y1var y2var xvar [if] [in] [, options]
options description
---------------------------------------------------------------------
vertical vertical area plot; the default
horizontal horizontal area plot
cmissing(y|n) missing values do not force gaps in area;
default is cmissing(y)
sort sort by xvar; recommended
area_options change the look of shaded areas
axis_choice_options associate plot with alternative axis
twoway_options titles, legends, axes, added lines and text, by,
regions, name, aspect ratio, etc.
---------------------------------------------------------------------
All explicit options are unique; see repeated options.
Menu
Graphics > Twoway graph (scatter, line, etc.)
Description
A range plot has two y variables, such as high and low daily stock prices
or upper and lower 95% confidence limits.
twoway rarea plots range as a shaded area.
Also see [G] graph twoway area for area plots filled to the axis.
Options
vertical and horizontal specify whether the high and low y values are to
be presented vertically (the default) or horizontally.
In the default vertical case, y1var and y2var record the minimum and
maximum (or maximum and minimum) y values to be graphed against each
xvar value.
If horizontal is specified, the values recorded in y1var and y2var
are plotted in the x direction and xvar is treated as the y value.
cmissing(y|n) specifies whether missing values are to be ignored when
drawing the area or if they are to create breaks in the area. The
default is cmissing(y), meaning that they are ignored. Consider the
following data:
+----------+
| y x |
|----------|
1. | 1 1 |
2. | 3 2 |
3. | 5 3 |
4. | . . |
5. | 6 5 |
|----------|
6. | 11 8 |
+----------+
Say that you graph these data by using twoway area y x. Do you want
a break in the area between 3 and 5? If so, you type
. twoway area y x, cmissing(n)
and two areas will be drawn, one for the observations before the
missing values at observation 4 and one for the observations after
the missing values.
If you omit the option (or type cmissing(y)), the data are treated as
if they contained
+----------+
| y x |
|----------|
1. | 1 1 |
2. | 3 2 |
3. | 5 3 |
4. | 6 5 |
5. | 11 8 |
+----------+
meaning that one contiguous area will be drawn over the range (1,8).
sort specifies that the data be sorted by xvar before plotting.
area_options set the look of the shaded areas. The most important of
these options is color(colorstyle), which specifies the color of both
the area and its outline; see [G] colorstyle for a list of color
choices. See [G] area_options for information on the other
area_options.
axis_choice_options associate the plot with a particular y or x axis on
the graph; see [G] axis_choice_options.
twoway_options are a set of common options supported by all twoway
graphs. These options allow you to title graphs, name graphs,
control axes and legends, add lines and text, set aspect ratios,
create graphs over by() groups, and change some advanced settings.
See [G] twoway_options.
Remarks
Remarks are presented under the following headings:
Typical use
Advanced use
Cautions
Typical use
We have daily data recording the values for the S&P 500 in 2001:
. sysuse sp500
. list date high low close in 1/5
+-----------------------------------------+
| date high low close |
|-----------------------------------------|
1. | 02jan2001 1320.28 1276.05 1283.27 |
2. | 03jan2001 1347.76 1274.62 1347.56 |
3. | 04jan2001 1350.24 1329.14 1333.34 |
4. | 05jan2001 1334.77 1294.95 1298.35 |
5. | 08jan2001 1298.35 1276.29 1295.86 |
+-----------------------------------------+
We will use the first 57 observations from these data:
. twoway rarea high low date in 1/57
(click to run)
Advanced use
rarea works particularly well when the upper and lower limits are smooth
functions and when the area is merely shaded rather than given an
eye-catching color:
. sysuse auto, clear
. quietly regress mpg weight
. predict hat
. predict s, stdf
. generate low = hat - 1.96*s
. generate hi = hat + 1.96*s
. twoway rarea low hi weight, sort color(gs14) ||
scatter mpg weight
(click to run)
Notice the use of option color() to change the color of the shaded area.
Also, we graphed the shaded area first and then the scatter. Typing
. twoway scatter ... || rarea ...
would not have produced the desired result because the shaded area would
have covered up the scatterplot.
Also see [G] graph twoway lfitci.
Cautions
Be sure that the data are in the order of xvar, or specify rarea's sort
option. If you do neither, you will get something that looks like modern
art; see Cautions in [G] graph twoway area for an example.
Also see
Manual: [G] graph twoway rarea
Help: [G] graph twoway area; [G] graph twoway rbar, [G] graph twoway
rspike, [G] graph twoway rcap, [G] graph twoway rcapsym, [G]
graph twoway rline, [G] graph twoway rconnected, [G] graph
twoway rscatter