• Stars
    star
    186
  • Rank 200,320 (Top 5 %)
  • Language
    R
  • Created over 10 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Edward Tufte-Inspired Slopegraphs

Tufte-Inspired Slopegraphs in R

This repository holds some working code for creating "slopegraphs" in R.

This is very much a work in progress. Once it's more stable, I will release the package to CRAN.

Pull requests welcome. Please report any issues on the issues page.

The package currently includes one mainfunction, slopegraph(), which produces a slopegraph from an observation-by-period data frame. Everything is more or less drawn automatically, but is highly customizable in terms of line and text colors, font sizes and styles, axes, titles, and plotting behind and in front of the slopegraph lines. An underlying function, segmentize() produces the data structure used for the actual plotting. And a new function, ggslopegraph() does the same as slopegraph() but using ggplot2 graphics.

Examples

The current output of the slopegraph() function (for the examples included in documentation) are shown below.

Tufte's most famous slopegraph example is probably the "cancer survival graph," depicting 5, 10, 15, and 20 year survival rates for various cancers. The first example mimics this result but draws it to the correct scale (unlike Tufte's original):

library("slopegraph")
data(cancer)
slopegraph(cancer, col.lines = 'gray', col.lab = "black", 
           xlim = c(-.5,5.5), cex.lab = 0.5, cex.num = 0.5,
           xlabels = c('5 Year','10 Year','15 Year','20 Year'))

Cancer Survival

The second example, also from Tufte, shows changes in gross domestic product for a small set of countries over two points in time:

data(gdp)
slopegraph(gdp, col.lines = 'gray', col.lab = "black", xlabels = c('1970','1979'),  
           main = 'Current Receipts of Goverment as a Percentage of Gross Domestic Product')

GDP

This third example comes from an 1878 publication (a copy of which is available here), showing the relative ranking of the population of various U.S. states. This example features a reversed y-axis to better display the ranking and I demonstrate the col.lines argument to highlight South Carolina:

data(states)
cols <- `[<-`(rep("black", 37), 7, "red")
slopegraph(states, xlim = c(-1, 12), ylim = c(37,0), offset.x = 0.06,
           col.lines = cols, col.lab = cols, 
           main = 'Relative Rank of U.S. State Populations, 1790-1870')

states

As of v0.1.9, there is also a ggplot2-based function, ggslopegraph() that produces a similar representation but using ggplot2 graphics:

require("ggplot2")
## Loading required package: ggplot2
data(states)
cols <- `[<-`(rep("black", 37), 7, "red")
ggslopegraph(states, offset.x = 0.06, yrev = TRUE,
  col.lines = cols, col.lab = cols, 
  main = 'Relative Rank of U.S. State Populations, 1790-1870') +
 theme_bw()    
## Warning: Removed 84 rows containing missing values (geom_text).

ggstates

Installation

CRAN Build Status Build status codecov.io Project Status: Work in Progress

To install the latest development version of slopegraph from GitHub:

if (!require("remotes")) {
    install.packages("remotes")
}
remotes::install_github("leeper/slopegraph")

More Repositories

1

rio

A Swiss-Army Knife for Data I/O
R
556
star
2

margins

An R Port of Stata's 'margins' Command
R
261
star
3

meme

Meme Generation in R
R
118
star
4

data-versioning

Collecting thoughts about data versioning
107
star
5

tttable

Defining a grammar of tables
92
star
6

prediction

Tidy, Type-Safe 'prediction()' Methods
R
87
star
7

csvy

Import and Export CSV Data With a YAML Metadata Header
R
53
star
8

conjoint-example

An Example Conjoint Experimental Design in Qualtrics
HTML
50
star
9

cregg

Simple Conjoint Analyses, Tidying, and Visualization
R
49
star
10

make-example

An example of using make for a data analysis project
R
32
star
11

pdfcount

An R Shiny App to Count Words in a PDF Document
R
28
star
12

htlatex-example

Demo of htlatex for LaTeX to Word (.docx) file conversion
TeX
26
star
13

reggie

Stata-like Regression Functionality for R
R
24
star
14

UNF

Tools for Creating Universal Numeric Fingerprints for Data
R
21
star
15

designcourse

Course materials for "Research Design in Political Science"
TeX
18
star
16

references

All of my bibliographic references
TeX
18
star
17

Depends

Quick demo of the risks of using 'Depends' in R packages
R
14
star
18

lumendb

Lumen Database (Chilling Effects) API Client
R
11
star
19

Rcourse

R Course Materials
HTML
11
star
20

surveycourse

Course materials for seminar on survey research methods
TeX
11
star
21

rite

rite: The Right Editor to Write R
R
8
star
22

rrcourse

Course Materials for Reproducible Research Workshop
TeX
8
star
23

lectures

Collection of files for miscellaneous talks and lectures
TeX
8
star
24

rpublons

Client for Publons.com
R
7
star
25

poliscitoys

Toy datasets for political science methods
7
star
26

lookfor

R port of Stata's lookfor command
R
7
star
27

rio.db

A Database Extension for 'rio'
R
6
star
28

webuse

Import Stata 'webuse' Datasets
R
6
star
29

surveyexpcourse

Materials for a short course on Survey Experiments
TeX
6
star
30

expcourse

Course materials for "Experimentation and Causal Inference"
TeX
6
star
31

responserates

AAPOR Survey Response Rates
R
6
star
32

arco

Select colors from the Tcl/tk `chooseColors` widget
R
5
star
33

textcolor

R
5
star
34

opinioncourse

Materials for "Public Opinion, Political Psychology, and Citizenship"
TeX
5
star
35

sparktex

Generate LaTeX sparklines in R
R
4
star
36

choco-r-devel

Chocolatey package for r-devel
PowerShell
4
star
37

apsa-leeper.bst

BibTeX style file for political science (adapted from apsa.bst)
4
star
38

interaction-plot

A simple shiny app for examining interaction effects
R
4
star
39

choco-rtools

Chocolatey package for Rtools
PowerShell
4
star
40

statcompcourse

Course materials for Introduction to Statistical Computing
TeX
3
star
41

Impressive

A fork of Martin Fiedler's Impressive presentation application
Python
3
star
42

websurveycourse

Materials for a short course on online surveys and survey experiments
TeX
3
star
43

conjoint-subgroups

Reproduction Materials for "Measuring Subgroup Preferences in Conjoint Experiments"
TeX
3
star
44

excel-vba-userform-marking

Some VBA for an Excel UserForm used for essay marking at LSE
Visual Basic
2
star
45

statapkg

A repo experimenting with installation of Stata packages from GitHub
HTML
2
star
46

regcourse

Some course materials about regression
TeX
2
star
47

GK2011

Gaines and Kuklinski (2011) Estimators for Hybrid Experiments
R
2
star
48

crandatapkgs

Find Data-Only Packages on CRAN
R
2
star
49

mcode

Functions to merge and recode across multiple variables
R
2
star
50

dual-axis

dual y-axis figures are usually terrible
R
2
star
51

mturkr-article

Materials for a short article about MTurkR
TeX
2
star
52

openfda

R
1
star
53

praiserror

A Sarcastic and Demoralizing Error Handler
R
1
star
54

ted-principle

Tidy Experimental Data: The TED Principle
HTML
1
star
55

ciplotm

Modified Version of Nick Cox's 'ciplot' ado for Stata
Stata
1
star
56

xyllabus

A Syllabus Markup Language
1
star
57

rcompiler

Automatically exported from code.google.com/p/rcompiler
C++
1
star
58

hints

Automatically exported from code.google.com/p/hints
TeX
1
star