Skip to Main Content

Graphics:Overview of Twoway Plots | Stata Learning Modules

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

Image defaul1-3

Line Plot

graph twoway line close date

Image defaul2-3

Connected Line Plot

graph twoway connected close date

Image defaul3-2

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

Image defaul4-2

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) )

Image defaul5-2

Area Graph

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

Image defaul6-2

Bar plot

graph twoway bar close date

Image defaul7-2

Spike plot

graph twoway spike close date

Image defaul8-4

Dropline plot

graph twoway dropline close date

Image defaul9-3

Dot plot

graph twoway dot change date

Image defaul10-4

Range plot with area shading

graph twoway rarea high low date

Image defaul11-3

Range plot with bars

graph twoway rbar high low date

Image defaul12-4

Range plot with spikes

graph twoway rspike high low date

Image defaul13-1

Range plot with capped spikes

graph twoway rcap high low date

Image defaul14-3

Range plot with spikes capped with symbols

graph twoway rcapsym high low date

Image defaul15

Range plot with markers

graph twoway rscatter high low date

Image defaul16

Range plot with lines

graph twoway rline high low date

Image defaul17

Range plot with lines and markers

graph twoway rconnected high low date

Image defaul18

Median band line plot

use https://stats.idre.ucla.edu/stat/stata/notes/hsb2, clear
graph twoway mband read write

Image defaul19

Spline line plot

graph twoway mspline read write

Image defaul20

LOWESS line plot

graph twoway lowess read write

Image defaul21

Linear prediction plot

graph twoway lfit read write

Image defaul22

Quadratic prediction plot

graph twoway qfit read write

Image defaul23

Fractional polynomial plot

graph twoway fpfit read write

Image defaul24

Linear prediction plot with confidence intervals

graph twoway lfitci read write

Image defaul25

Quadratic plot with confidence intervals

graph twoway qfitci read write

Image defaul26

Fractional polynomial plot with CIs

graph twoway fpfitci read write

Image defaul27

Histogram

graph twoway histogram read

Image defaul28

Kernel density plot

graph twoway kdensity read 

Image defaul29

Function plot

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

Image defaul30