ggslopegraph2: Plot a Slopegraph a la Tufte using dplyr and ggplot2

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/ggslopegraph2.R

Description

Creates a "slopegraph" as conceptualized by Edward Tufte. Slopegraphs are minimalist and efficient presentations of your data that can simultaneously convey the relative rankings, the actual numeric values, and the changes and directionality of the data over time. Takes a dataframe as input, with three named columns being used to draw the plot. Makes the required adjustments to the ggplot2 parameters and returns the plot.

Usage

1
2
3
4
5
6
ggslopegraph2(dataframe, times, measurement, grouping, title = "",
  subtitle = "", caption = "", xtextsize = 12, ytextsize = 3,
  titletextsize = 14, subtitletextsize = 10, captiontextsize = 8,
  linethickness = 1, linecolor = "ByGroup", datatextsize = 2.5,
  datatextfamily = "sans", datatextface = "plain",
  labeltextfamily = "sans", labeltextface = "bold")

Arguments

dataframe

a dataframe or an object that can be coerced to a dataframe. Basic error checking is performed, to include ensuring that the named columns exist in the dataframe. See the cancer2 dataset for an example of how the dataframe should be organized.

times

a column inside the dataframe that will be plotted on the x axis. Traditionally this is some measure of time. The function accepts a column of class ordered, factor or character. NOTE if your variable is currently a "date" class you must convert before using the function with as.character(variablename).

measurement

a column inside the dataframe that will be plotted on the y axis. Traditionally this is some measure such as a percentage. Currently the function accepts a column of type integer or numeric. The slopegraph will be most effective when the measurements are not too disparate.

grouping

a column inside the dataframe that will be used to group and distinguish measurements.

title

Optionally the title to be displayed. title = NULL will remove it entirely. title = "" will provide an empty title but retain the spacing.

subtitle

Optionally the sub-title to be displayed. subtitle = NULL will remove it entirely. subtitle = "" will provide an empty subtitle but retain the spacing.

caption

Optionally the caption to be displayed. caption = NULL will remove it entirely. caption = "" will provide an empty title but retain the spacing.

xtextsize

Optionally the font size for the X axis labels to be displayed. xtextsize = 12 is the default must be a numeric. Note that X & Y axis text are on different scales

ytextsize

Optionally the font size for the Y axis labels to be displayed. ytextsize = 3 is the default must be a numeric. Note that X & Y axis text are on different scales

titletextsize

Optionally the font size for the title to be displayed. titletextsize = 14 is the default must be a numeric.

subtitletextsize

Optionally the font size for the subtitle to be displayed. subtitletextsize = 10 is the default must be a numeric.

captiontextsize

Optionally the font size for the caption to be displayed. captiontextsize = 8 is the default must be a numeric.

linethickness

Optionally the thickness of the plotted lines. linethickness = 1 is the default must be a numeric.

linecolor

Optionally the color of the plotted lines. By default it will use the ggplot2 color palette for coloring by Grouping. The user may override with one valid color of their choice e.g. "black" (see colors() for choices) OR they may provide a vector of colors such as c("gray", "red", "green", "gray", "blue") OR a named vector like c("Green" = "gray", "Liberal" = "red", "NDP" = "green", "Others" = "gray", "PC" = "blue"). Any input must be character, and the length of a vector should equal the number of levels in Grouping. If the user does not provide enough colors they will be recycled.

datatextsize

Optionally the font size of the plotted data points. datatextsize = 2.5 is the default must be a numeric.

datatextfamily

Optionally the font family of the plotted data points. datatextfamily = "sans" is the default.

datatextface

Optionally the font face of the plotted data points. datatextface = "plain" is the default.

labeltextfamily

Optionally the font family of the grouping labels. labeltextfamily = "sans" is the default.

labeltextface

Optionally the font face of the grouping labels. labeltextface = "bold" is the default.

Details

formatting changes as well as major changes to linecolor

Value

A ggplot object.

Author(s)

Chuck Powell

See Also

For a observation-by-time data frame interface, see ggslopegraph.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# basic graph
ggslopegraph2(cancer2, Year, Survival, Type,
              title = "Estimates of Percent Survival Rates")

# with further customization
ggslopegraph2(cancer2, Year, Survival, Type, 
              title = "Estimates of Percent Survival Rates", 
              linecolor = "black", 
              linethickness = 1, 
              subtitle = NULL, 
              caption = NULL)
              
# demonstrating linecolor recyclng
ggslopegraph2(cancer2, Year, Survival, Type, 
              title = "Estimates of Percent Survival Rates", 
              subtitle = "Based on: Edward Tufte, Beautiful Evidence, 174, 176.",
              caption = "https://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0003nk",
              linecolor = c("black", "red", "grey"), 
              linethickness = .5)

leeper/slopegraph documentation built on May 21, 2019, 1:39 a.m.