doc_plot: Add documentation to ggplot2 plots

Description Usage Arguments Value Examples

View source: R/doc_plot.R

Description

Adds documentation elements such as sponsor, author, author job title, and data sources to annotate ggplot2 plots. Documentation is one of the principles of analytical design according to Edward Tufte's "Beautiful Evidence".

Usage

1
2
doc_plot(g, author = "", author_title = "", data_source = "",
  date = FALSE, img_sponsor = "", sponsor = "", theme = "gray", ...)

Arguments

g

A ggplot2 object to which documentation is to be added.

author

A character object indicating the author of the plot.

author_title

A character object indicating the job title of the author of the plot.

data_source

A character object indicating the sources of the data displayed in the plot.

date

A logical indicating whether or not to add today's date as the publishing date of the plot. It defaults to FALSE.

img_sponsor

A character object representing the filename/filepath to a *.png image file representing the sponsor (ie. company logo)

sponsor

A character object indicating the sponsor of the plot. Ignored if img_sponsor is used.

theme

A character object indicating the theme for the documentation. This value should correspond to themes from the ggplot2 or ggthemes packages. It defaults to 'gray'.

...

Additional parameters to be passed into the get_theme() function.

Value

The object to be plotted.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
library("ggdocumentation")

# works with ggplot2 quick plots!
g <- qplot(Sepal.Length, Petal.Length, data=iris, color=Species)

# add documentation - automatically draws to canvas
doc_plot(g,
         author="Joshua Poirier",
         data_source="Fisher, 1936",
         sponsor="MVP")

# works with themes from ggthemes package!
library("ggthemes")
g <- ggplot(data=iris, aes(x=Sepal.Length, y=Petal.Length, col=Species)) +
     labs(title="Iris data using 'ggdocumentation'") +
     scale_color_fivethirtyeight() +
     theme_fivethirtyeight() +
     geom_point()
     
doc_plot(g, 
         author="Joshua Poirier",
         author_title="Data Scientist",
         data_source="Fisher, 1936",
         date=TRUE,
         img_sponsor="figures/mvp-logo.png",
         theme="fivethirtyeight")

# works with faceted plots too!
g <- ggplot(iris, aes(Sepal.Length, Petal.Length, col=Species)) +
     labs(title="Iris data using 'ggdocumentation'!") +
     facet_grid(. ~ Species) +
     scale_color_economist() +
     theme_economist(dkpanel=TRUE) +
     geom_point()

doc_plot(g,
         author="Joshua Poirier",
         data_source="Fisher, 1936",
         img_sponsor="figures/mvp-logo.png",
         theme="economist",
         dkpanel=TRUE)

joshuaadampoirier/ggdocumentation documentation built on May 19, 2019, 8:54 p.m.