Skip to Main Content

Graphics: Common Graph Options | 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
.


Adding a title

graph twoway scatter read write, ///
  title("Scatterplot of Reading and Writing")

Image defaul1-2


Black title, positioned at 11 O’Clock

graph twoway scatter read write, ///
  title("Scatterplot of Reading and Writing", ///
  color(black) position(11))

Image defaul2-2


Title at 5 O’Clock, medium size text, positioned within the graph

graph twoway scatter read write, ///
  title("Scatterplot of Reading and Writing", ///
  size(medium) position(5) ring(0))

Image defaul3-1


Title in a box with cyan background, magenta border
and a medium margin around the title

graph twoway scatter read write, ///
  title("Scatterplot of Reading and Writing", ///
         box bcolor(cyan) blcolor(magenta) bmargin(medium)) 

Image defaul4-1


Two line title with a gap of 3 between the titles

graph twoway scatter read write, ///
  title("Scatterplot of Reading and Writing" ///
  "Sample of 200 Students", linegap(3) )

Image defaul5-1


Graph with title, subtitle, caption, and a note

graph twoway scatter read write, ///
  title("Scatterplot of Reading and Writing") /// 
  subtitle("Sample of 200 Students") ///
  note(High School and Beyond Data) ///
  caption(From www.ats.ucla.edu)

Image defaul6-1


Moving and sizing note and caption

graph twoway scatter read write, ///
  title("Scatterplot of Reading and Writing") ///
  subtitle("Sample of 200 Students") ///
  note(High School and Beyond Data, size(medium) position(5)) /// 
  caption(From www.ats.ucla.edu, size(vsmall) position(5))

Image defaul7-1


Modifying title on x and y axis

twoway scatter read write, ///
  ytitle(Score on Writing Test) ///
  xtitle(Score on Reading Test) 

Image defaul8-3


Complete example

twoway scatter read write, ///
  title("Scatterplot of Reading and Writing") ///
  subtitle("Sample of 200 Students") ///
  note(High School and Beyond Data, size(medium) position(5)) /// 
  caption(From www.ats.ucla.edu, size(vsmall) position(5)) ///
  ytitle(Score on Writing Test) ///
  xtitle(Score on Reading Test)

Image defaul9-2


Sizing graph to have 4 by 2 aspect ratio

twoway scatter read write, ysize(2) xsize(4)

Image defaul10-3


Making text scaled 1.5 times normal size

graph twoway scatter read write, scale(1.5)

Image defaul11-2


Graph with sand color outside graph, gray inside graph

graph twoway scatter read write, ///
  title("Scatterplot of Reading and Writing") /// 
  graphregion( color(sand) ) plotregion(  fcolor(gray) )

Image defaul12-3


Graph with sand color outside graph, gray inside graph,
red outer border, blue inner border

graph twoway scatter read write, ///
  title("Scatterplot of Reading and Writing") /// 
  graphregion( fcolor(red)  ifcolor(sand) ) ///
  plotregion(  fcolor(blue) ifcolor(gray))

Image defaul13


Graph with colors for many border elements

graph twoway scatter read write, ///
  title("Scatterplot of Reading and Writing") /// 
  graphregion( fcolor(red)   lcolor(yellow)    lwidth(thick)  ///
              ifcolor(sand) ilcolor(orange) ilwidth(thick)) ///
  plotregion(  fcolor(blue)  lcolor(green)    lwidth(thick)  ///
              ifcolor(gray) ilcolor(purple)   ilwidth(thick))

Image defaul14-2