Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann...

41
Customizing Stata graphs made easy Ben Jann University of Bern, [email protected] 2018 German Stata Users Group meeting University of Konstanz, June 22, 2018 Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 1

Transcript of Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann...

Page 1: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Customizing Stata graphs made easy

Ben Jann

University of Bern, [email protected]

2018 German Stata Users Group meetingUniversity of Konstanz, June 22, 2018

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 1

Page 2: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Outline

1 Introduction

2 Overview of new Stata commands

3 Basic procedure

4 Composite settings

5 Summary

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 2

Page 3: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Stata’s graph schemes

Stata provides a number of so-called schemes that define the overalllook of graphs.

Some examples are as follows.

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 3

Page 4: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

. sysuse auto, clear(1978 Automobile Data). separate price, by(rep) shortlabel

(output omitted ). set scheme s2color. scatter price? weight, ytitle(Price)

05,

000

10,0

0015

,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1 rep78 == 2rep78 == 3 rep78 == 4rep78 == 5

. set scheme s1mono

. scatter price? weight, ytitle(Price)

05,

000

10,0

0015

,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1 rep78 == 2rep78 == 3 rep78 == 4rep78 == 5

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 4

Page 5: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

. set scheme economist

. scatter price? weight, ytitle(Price)

0

5,000

10,000

15,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1 rep78 == 2 rep78 == 3rep78 == 4 rep78 == 5

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 5

Page 6: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

User contributed schemes

The number of available schemes in official Stata is somewhatlimited.

Hence, some users took the effort to develop custom scheme filesand make them publicly available.

Examples are as follows.

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 6

Page 7: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Atz (2011)

. set scheme tufte

. scatter price? weight, ytitle(Price)

0

5,000

10,000

15,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1rep78 == 2rep78 == 3rep78 == 4rep78 == 5

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 7

Page 8: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Bischof (2017a). scatter price? weight, ytitle(Price) ///> scheme(538)

0

5,000

10,000

15,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1rep78 == 2rep78 == 3rep78 == 4rep78 == 5

. scatter price? weight, ytitle(Price) ///> scheme(538bw)

0

5,000

10,000

15,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1rep78 == 2rep78 == 3rep78 == 4rep78 == 5

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 8

Page 9: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Bischof (2017b). set scheme plotplain. scatter price? weight, ytitle(Price)

0

5,000

10,000

15,000

Pric

e

2,000 3,000 4,000 5,000

Weight (lbs.)

rep78 == 1rep78 == 2rep78 == 3rep78 == 4rep78 == 5

. set scheme plotplainblind

. scatter price? weight, ytitle(Price)

0

5,000

10,000

15,000

Pric

e

2,000 3,000 4,000 5,000

Weight (lbs.)

rep78 == 1rep78 == 2rep78 == 3rep78 == 4rep78 == 5

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 9

Page 10: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Bischof (2017b). set scheme plottig. scatter price? weight, ytitle(Price)

0

5,000

10,000

15,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1rep78 == 2rep78 == 3rep78 == 4rep78 == 5

. set scheme plottigblind

. scatter price? weight, ytitle(Price)(note: clockdir zyx2legend_position not found in scheme, default attributes used)

0

5,000

10,000

15,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1rep78 == 2rep78 == 3rep78 == 4rep78 == 5

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 10

Page 11: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Briatte (2013). set scheme burd. scatter price? weight, ytitle(Price)

0

5,000

10,000

15,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1 rep78 == 2rep78 == 3 rep78 == 4rep78 == 5

. set scheme burd5

. graph hbar price?, stack percent over(foreign)

0 20 40 60 80 100percent

Foreign

Domestic

mean of price1 mean of price2mean of price3 mean of price4mean of price5

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 11

Page 12: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Juul (2003). set scheme lean1. scatter price? weight, ytitle(Price)

0

5,000

10,000

15,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1rep78 == 2rep78 == 3rep78 == 4rep78 == 5

. set scheme lean2

. scatter price? weight, ytitle(Price)

0

5,000

10,000

15,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1rep78 == 2rep78 == 3rep78 == 4rep78 == 5

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 12

Page 13: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Morris (2013, 2015). set scheme mrc. scatter price? weight, ytitle(Price)

0

5,000

10,000

15,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1 rep78 == 2rep78 == 3 rep78 == 4rep78 == 5

. set scheme tfl

. scatter price? weight, ytitle(Price)(note: anglestyle symbol not found in scheme, default attributes used)(note: anglestyle symbol not found in scheme, default attributes used)

0

5,000

10,000

15,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1 rep78 == 2rep78 == 3 rep78 == 4rep78 == 5

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 13

Page 14: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Newson (2005). set scheme rbn1mono. scatter price? weight, ytitle(Price)

0

5,000

10,000

15,000

Pric

e

2,000

3,000

4,000

5,000

Weight (lbs.)

rep78 == 1rep78 == 2rep78 == 3rep78 == 4rep78 == 5

. set scheme rbn3mono

. scatter price? weight, ytitle(Price)

0

5,000

10,000

15,000

Pric

e

2,000

3,000

4,000

5,000

Weight (lbs.)

rep78 == 1rep78 == 2rep78 == 3rep78 == 4rep78 == 5

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 14

Page 15: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Personal schemes

These additional schemes might provide useful, but most likely noneof them will do exactly what you want.

Therefore, some users also create their personal scheme (forexample, by modifying one of the schemes above and storing itunder a new name in an appropriate place in the local system).

A problem, however, is that what you want depends on context(properties of the data, type of analysis, nature of results, context inwhich graphs are used, audience to which the graphs are presented,. . . ).

This means that you have to create a new scheme file each time youwant to change some detail. This is very tedious and it is difficult tokeep an overview.

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 15

Page 16: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Dynamic schemes

My argument is that graph settings should be dynamic in the sensethat they are defined in the do-file that creates the graphs.

That is, graph settings should not be part of the local system, theyshould be part of the analysis script.

This is much more convenient. It also has the advantage thateverything needed to reproduce your graphs can be included in asingle file.

The new grstyle package supports such practice. It providescommands that let you change the graph settings on the fly. Itworks by maintaining a temporary scheme file in the background.

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 16

Page 17: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Outline

1 Introduction

2 Overview of new Stata commands

3 Basic procedure

4 Composite settings

5 Summary

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 17

Page 18: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Overview of new Stata commands

There are two new packages: grstyle and palettes.

The grstyle package contains commands to change graph settingsfrom within a do-file.

grstyle init initialize the settingsgrstyle scheme entry add a single scheme entrygrstyle set ... add composite settingsgrstyle type view the settingsgrstyle clear clear the settings

The palettes package contains commands to manage colors,marker symbols, and line patterns. These commands are used bygrstyle, but they can also be used separately.

colorpalette retrieve a color palettesymbolpalette retrieve a symbol palettelinepalette retrieve a line pattern palette

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 18

Page 19: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Outline

1 Introduction

2 Overview of new Stata commands

3 Basic procedure

4 Composite settings

5 Summary

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 19

Page 20: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Basic procedure

The basic procedure is to first call grstyle init, then add thedesired settings using a series of grstyle commands, and thencreate the graphs:

set scheme schemename

grstyle init

grstyle ...

grstyle ......

graph command

graph command...

grstyle clear

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 20

Page 21: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Example

Here’s the graph of before, using the s2color scheme (Stata’sdefault):

. set scheme s2color

. scatter price? weight, ytitle(Price)

05,

000

10,0

0015

,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1 rep78 == 2rep78 == 3 rep78 == 4rep78 == 5

Now let’s change how things look.

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 21

Page 22: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Example

Step 1: get rid of background color, change the rendering of thegrid, use horizontal labels on the Y axis

. grstyle init

. grstyle color background white

. grstyle color major_grid dimgray

. grstyle linewidth major_grid thin

. grstyle yesno draw_major_hgrid yes

. grstyle yesno grid_draw_min yes

. grstyle yesno grid_draw_max yes

. grstyle anglestyle vertical_tick horizontal

. scatter price? weight, ytitle(Price)

0

5,000

10,000

15,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1 rep78 == 2rep78 == 3 rep78 == 4rep78 == 5

The settings added by grstyle use scheme entry syntax. Thesyntax of scheme entries is

attribute element style

See help scheme entries.

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 22

Page 23: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Example

Step 2: use larger marker symbols and make them transparent

. grstyle symbolsize p large

. grstyle color p1markline navy%0

. grstyle color p1markfill navy%70

. grstyle color p2markline maroon%0

. grstyle color p2markfill maroon%70

. grstyle color p3markline forest_green%0

. grstyle color p3markfill forest_green%70

. grstyle color p4markline dkorange%0

. grstyle color p4markfill dkorange%70

. grstyle color p5markline teal%0

. grstyle color p5markfill teal%70

. scatter price? weight, ytitle(Price)

0

5,000

10,000

15,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1 rep78 == 2rep78 == 3 rep78 == 4rep78 == 5

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 23

Page 24: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Example

Step 3: move the legend to the right and remove the frame

. grstyle clockdir legend_position 4

. grstyle numstyle legend_cols 1

. grstyle linestyle legend none

. scatter price? weight, ytitle(Price)

0

5,000

10,000

15,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1rep78 == 2rep78 == 3rep78 == 4rep78 == 5

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 24

Page 25: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Example

Revert back to original.

. grstyle clear

. scatter price? weight, ytitle(Price)

05,

000

10,0

0015

,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1 rep78 == 2rep78 == 3 rep78 == 4rep78 == 5

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 25

Page 26: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Outline

1 Introduction

2 Overview of new Stata commands

3 Basic procedure

4 Composite settings

5 Summary

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 26

Page 27: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Composite settings

I assume you got the idea.But you probably ask yourself:I “Wasn’t the goal to make things easy? This still looks prettycomplicated to me.”

Yes, scheme entry syntax (see help scheme entries) is unfamiliarand hard to remember.

This is why there is a command called grstyle set that can beused to generate scheme entries for some frequently used settings.

grstyle set has various subcommands to determine the style ofbackground and coordinate system, the legend, confidence areas,colors, symbols, line pattern, and sizes.

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 27

Page 28: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Background and coordinate system

. grstyle init

. grstyle set plain, horizontal grid noextend

. scatter price? weight, ytitle(Price)

0

5,000

10,000

15,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1 rep78 == 2rep78 == 3 rep78 == 4rep78 == 5

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 28

Page 29: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

. grstyle init

. grstyle set mesh, horizontal compact minor

. scatter price? weight, ytitle(Price)

0

5,000

10,000

15,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1 rep78 == 2rep78 == 3 rep78 == 4rep78 == 5

. grstyle init

. grstyle set imesh, horizontal minor

. scatter price? weight, ytitle(Price)

0

5,000

10,000

15,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1 rep78 == 2rep78 == 3 rep78 == 4rep78 == 5

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 29

Page 30: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

The legend. grstyle init. grstyle set plain. grstyle set legend 10, inside. scatter price? weight, ytitle(Price)

05,

000

10,0

0015

,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1rep78 == 2rep78 == 3rep78 == 4rep78 == 5

. grstyle init

. grstyle set imesh, horizontal compact minor

. grstyle set legend 4, nobox

. scatter price? weight, ytitle(Price)

0

5,000

10,000

15,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1rep78 == 2rep78 == 3rep78 == 4rep78 == 5

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 30

Page 31: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Transparent CIs

. grstyle init

. grstyle set plain, grid

. grstyle set ci

. twoway (scatter price? length) ///> (lpolyci price length if foreign==0) ///> (lpolyci price length if foreign==1) ///> , ytitle(Price) legend(off)

05,000

10,000

15,000

Price

140 160 180 200 220 240

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 31

Page 32: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Colors. grstyle init. grstyle set imesh, horizontal compact minor. grstyle set legend 4, nobox. grstyle set color hue, n(5) opacity(50). grstyle set symbolsize large. scatter price? weight, ytitle(Price)

0

5,000

10,000

15,000

Pric

e

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 1rep78 == 2rep78 == 3rep78 == 4rep78 == 5

. grstyle init

. grstyle set plain

. grstyle set color RdYlGn, n(5)

. graph hbar price?, stack percent ///> over(foreign) legend(off)

0 20 40 60 80 100percent

Foreign

Domestic

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 32

Page 33: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Colors

A large number of color palettes is available.I palettes from official Stata’s scheme filesI palettes from user contributed scheme filesI HCL (Hue-Chroma-Luminance) and HSV (Hue-Saturation-Value)color generators

I palette collections such as ColorBrewer (Brewer et al. 2003)I etc.

Can also specify custom colors in RGB, CMYK, HSV, HCL, or Hex(web colors).

Can adjust intensity and opacity (Stata 15).

See http://repec.sowi.unibe.ch/stata/palettes/

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 33

Page 34: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Symbols and line patterns

. grstyle init

. grstyle set plain

. grstyle set color Set1

. grstyle set symbol

. grstyle set lpattern

. twoway (connected price3-price5 weight, sort), ///> ytitle(Price) 0

5,00

010

,000

15,0

00Pr

ice

2,000 3,000 4,000 5,000Weight (lbs.)

rep78 == 3 rep78 == 4rep78 == 5

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 34

Page 35: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Sizes

A specific feature of grstyle set is that it can set absolute sizes(inch, pt, cm, or mm).

Sizes in Stata graphs are always relative. The procedure therefore isto first use grstyle set graphsize to determine the size of thegraph.

After that, use grstyle set size to set the size of text etc. Thereare also commands for symbol sizes, line widths, and margins.

Of course, the target sizes will only be preserved as long as you donot change the graph size.

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 35

Page 36: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Sizes

. grstyle init

. grstyle set plain, grid

. grstyle set legend 2

. grstyle set symbol Oh

. grstyle set graphsize 6cm 9cm

. grstyle set size 10pt: heading

. grstyle set size 8pt: subheading axis_title

. grstyle set size 6pt: tick_label key_label

. grstyle set symbolsize 1 2 3 4 5, pt

. grstyle set linewidth .8pt: plineplot

. grstyle set linewidth .4pt: pmark legend axisline tick major_grid

. grstyle set margin zero

. twoway (scatter price? weight) (lfit price weight), title("Title (10pt)") ///> subtitle("Subtitle (8pt)") xtitle("X axis title (8pt)") ///> ytitle("Y axis title (8pt)") ///> legend(order(1 "1pt" 2 "2pt" 3 "3pt" 4 "4pt" 5 "5pt" 6 ".8pt"))

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 36

Page 37: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Sizes

05,

000

10,0

0015

,000

Y ax

is ti

tle (8

pt)

2,000 3,000 4,000 5,000X axis title (8pt)

1pt2pt3pt4pt5pt.8pt

Subtitle (8pt)Title (10pt)

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 37

Page 38: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Contents

1 Introduction

2 Overview of new Stata commands

3 Basic procedure

4 Composite settings

5 Summary

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 38

Page 39: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

Summary

grstyle provides a tool to change graph settings from within ado-file. Manual editing of scheme files is no longer needed.

grstyle set is a powerful convenience command to define a widevariety of style settings without having to know much about schemeentry syntax.

colorpalette provides a versatile color management system.More information and examples:I http://repec.sowi.unibe.ch/stata/grstyleI http://repec.sowi.unibe.ch/stata/palettes

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 39

Page 40: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

References

Atz, U. 2011. SCHEME_TUFTE: Stata module to provide a Tufte-inspiredgraphics scheme. Available fromhttps://ideas.repec.org/c/boc/bocode/s457285.html.

Bischof, D. 2017a. G538SCHEMES: module to provide graphics schemes forhttp://fivethirtyeight.com. Available fromhttp://ideas.repec.org/c/boc/bocode/s458404.html.

Bischof, D. 2017b. New graphic schemes for Stata: plotplain and plottig. TheStata Journal 17(3): 748–759.

Brewer, C. A., G. W. Hatchard, M. A. Harrower. 2003. ColorBrewer in Print: ACatalog of Color Schemes for Maps. Cartography and Geographic InformationScience 30(1): 5–32.

Briatte, F. 2013. SCHEME-BURD: Stata module to provide aColorBrewer-inspired graphics scheme with qualitative and blue-to-red divergingcolors. Available from http://ideas.repec.org/c/boc/bocode/s457623.html.

Buchanan, B. 2015. BREWSCHEME: Stata module for generating customizedgraph scheme files. Available fromhttp://ideas.repec.org/c/boc/bocode/s458050.html.

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 40

Page 41: Customizing Stata graphs made easy · 2018-08-13 · CustomizingStatagraphsmadeeasy BenJann University of Bern, ben.jann@soz.unibe.ch 2018GermanStataUsersGroupmeeting UniversityofKonstanz,June22,2018

References

Juul, S. 2003. Lean mainstream schemes for Stata 8 graphics. The Stata Journal3(3): 295-301.

Morris, T. 2013. SCHEME-MRC: Stata module to provide graphics scheme forUK Medical Research Council. Available fromhttp://ideas.repec.org/c/boc/bocode/s457703.html.

Morris, T. 2015. SCHEME-TFL: Stata module to provide graph scheme, basedon Transport for London’s corporate colour pallette. Available fromhttp://ideas.repec.org/c/boc/bocode/s458103.html.

Newson, R. 2005. SCHEME_RBN1MONO: Stata module to provide minimalmonochrome graphics schemes. Statistical Software Components S456505,Boston College Department of Economics. Available fromhttps://ideas.repec.org/c/boc/bocode/s456505.html.

Ben Jann (University of Bern) grstyle Konstanz, 22.06.2018 41