← See Stata 19's features
Highlights
Create a heat map
Plot a value and range, such as a mean and corresponding confidence intervals (CIs)
Use spikes or capped spikes for the range
New in graph bar
Plot CIs for means
Group bars by y variables
Add a prefix or suffix to bar labels
Customize the ticks and labels on the categorical axis
New in graph dot
Plot CIs for means
Group dots by y variables
Customize the ticks and labels on the categorical axis
New in graph box
Group boxes by y variables
Customize the ticks and labels on the categorical axis
Specify colors using hexadecimal values
Add a prefix or suffix to marker labels
See more graphics features
Want to create a heat map displaying the level of criminal activity in different counties for multiple years? Or a bar graph of the average wage by industry with confidence intervals? Or a box plot of several measures of health for males and females, with boxes grouped by the y variables? Or perhaps a range plot for high and low stock prices with markers for the opening price? With Stata’s new two-way plottypes and graphics features, you can create any of these graphs.
Stata 19 supports a new two-way plottype heatmap to create a heat map, which displays values of z across values of y and x as a grid of colored rectangles. These plots are associated with displaying values of temperature, but more generally can be used to display levels of a numeric variable, such as elevation or criminal activity.
Stata 19 also has two other new two-way plottypes, rpcap and rpspike, which plot a value and range, such as high, low, and opening daily stock prices. To connect the high and low values, rpcap uses a capped spike, and rpspike uses a spike. Both use a marker for the opening value.
Additionally, new features have been added to graph bar, graph dot, and graph box. New options are available to control which ticks and labels should be displayed on the categorical axis. And, new option groupyvars allows you to group bars, dots, and boxes based on the y variables. Also, graph bar and graph dot support a new statistic, meanci, which plots the mean and its confidence interval. Additionally, you can add a prefix or suffix to bar labels.
-> Heat map
-> Bar graph
-> Means and confidence intervals
-> Group bars by y variables
-> Range and point plots
A heat map displays values of z across values of y and x as a grid of colored rectangles. The observations are binned by y and x grids. Below, we create a heat map displaying monthly average temperatures for College Station, Texas, from 2000 to 2024:
. webuse cstemp (Monthly average temperature for College Station, Texas) . twoway heatmap temp month year, ylabel(1(1)12, valuelabel) ccuts(45(5)95)
Each rectangle represents a month in a year, and we fill in each rectangle with a color based on the temperature. We specified the cutpoints for the levels of temperature, from 45 to 95, in increments of 5; this gives us differently colored rectangles for different temperature levels.
We can easily add prefixes and suffixes to the bar labels. For example, we could suffix the bar labels with a percent sign:
. sysuse citytemp (City temperature data) . graph bar, over(division) blabel(bar, format(%4.2f) suffix(%))
Or we could prefix the bar labels with a bold “$” sign and make the labels italic:
. sysuse auto (1978 automobile data) . graph bar price, over(foreign) blabel(bar, prefix("{bf:$}{it:") suffix("}"))
We may specify meanci to display the mean value with a confidence interval line. For example, we plot the average wage for different occupations, and the corresponding confidence interval:
. webuse nlsw88 (NLSW, 1988 extract) . graph bar (meanci) wage, over(occupation) over(union) asyvars
We may specify the groupyvars option to group bars belonging to the same y variables instead of grouping bars based on categories of the over() variable. For example, below we plot the mean systolic and diastolic blood pressure for individuals in different age groups:
. webuse nhanes2 . graph hbar bpsystol bpdiast, over(agegrp) groupyvars
We can easily plot a value and range with plottypes rpcap and rpspike. For example, we want to display the range of high and low stock prices along with the daily opening price. To connect the high and low values, rpcap uses a capped spike and rpspike uses a spike. Both use a marker for the opening value.
. sysuse sp500 (S&P 500) . twoway rpcap high low open date in 1/15
. twoway rpspike high low open date in 1/15
Read more about the new two-way plottypes heatmap, rpcap, and rpspike in [G-2] graph twoway heatmap, [G-2] graph twoway rpcap, and [G-2] graph twoway rpspike in the Stata Graphics Reference Manual.
Learn more about Stata's publication-quality graphics.
View all the new features in Stata 19.