Stata Learning Module
Graphics: Overview of Twoway Plots

This module shows examples of the different kinds of graphs that can be created with the graph twoway command.  This is illustrated by showing the command and the resulting graph.  For more information, see the Stata Graphics Manual available over the web and from within Stata by typing help graph, and in particular the section on Two Way Scatterplots.

Basic twoway scatterplot

sysuse sp500
graph twoway scatter close date

 

Line Plot

graph twoway line close date

 

Connected Line Plot

graph twoway connected close date

Immediate scatterplot

graph twoway scatteri ///
  965.8    15239 (3) "Low   965.8" ///
  1373.73  15005 (3) "High 1373.73" , msymbol(i)

Note: Including (3) denotes the label position, by default labels are positioned at 3 o'clock

Scatterplot and Immediate Scatterplot

graph twoway ///
  (scatter close date) ///
  (scatteri  965.8  15239 (3) "Low, 9/21, 965.8" ///
            1373.7  15005 (3) "High, 1/30, 1373.7", msymbol(i) )

Area Graph

drop if _n > 57
graph twoway area close date, sort

 

Bar plot

graph twoway bar close date

 

Spike plot

graph twoway spike close date

 

Dropline plot

graph twoway dropline close date

 

Dot plot

graph twoway dot change date

 

Range plot with area shading

graph twoway rarea high low date

 

Range plot with bars

graph twoway rbar high low date

 

Range plot with spikes

graph twoway rspike high low date

 

Range plot with capped spikes

graph twoway rcap high low date

 

Range plot with spikes capped with symbols

graph twoway rcapsym high low date

 

Range plot with markers

graph twoway rscatter high low date

 

Range plot with lines

graph twoway rline high low date

 

Range plot with lines and markers

graph twoway rconnected high low date

 

Median band line plot

use http://www.ats.ucla.edu/stat/stata/notes/hsb2, clear
graph twoway mband read write

 

Spline line plot

graph twoway mspline read write

 

LOWESS line plot

graph twoway lowess read write

 

Linear prediction plot

graph twoway lfit read write

 

Quadratic prediction plot

graph twoway qfit read write

 

Fractional polynomial plot

graph twoway fpfit read write

 

Linear prediction plot with confidence intervals

graph twoway lfitci read write

 

Quadratic plot with confidence intervals

graph twoway qfitci read write

 

Fractional polynomial plot with CIs

graph twoway fpfitci read write

 

Histogram

graph twoway histogram read

 

Kernel density plot

graph twoway kdensity read 

 

Function plot

graph twoway function y=normden(x), range(-4 4)

How to cite this page

Report an error on this page or leave a comment

The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.