plot_footnote: Adding footnote to the 'ggplot' object

Description Usage Arguments Value Examples

View source: R/plot_footnote.R

Description

This function adds footnote to the ggplot object and returns gtable object.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
plot_footnote(
  p,
  note,
  caption = FALSE,
  fontsize = NULL,
  fontcol = "black",
  align = "right",
  distance.from.side = 0.05,
  distance.from.bottom = 0.75,
  bottom.expand.rate = NULL,
  show.plot = TRUE
)

Arguments

p

ggplot object.

note

The content of footnote (character). Line break is allowed by using \n.

caption

Use caption option in ggplot2. If TRUE, all following options are ignored.

fontsize

The size of font. If NULL (default), the size is set to the the font size in text setting of p - 1.

fontcol

The color of the font. The default is "black".

align

The alignment of the footnote text. Either "right" or "left".

distance.from.side

The horizontal distance of notes from the edge of graph space by the proportion of graph width (numeric: 0-1). The default is 0.05. The distance is measured from the side specified in align.

distance.from.bottom

The vertical distance of notes from the bottom of graph bottom by the proportion of bottom graph margin height (numeric: 0-1). The default is 0.75.

bottom.expand.rate

The expansion rate of the bottom margin of the graph to incorporate footnote (numeric). The value of 1 indicates no expansion. If NULL (default), it is set to the number of lines in note + 1.

show.plot

Print the plot at the end of function (boulean). The default is TRUE.

Value

gtable object. It is impossible to add aditional ggplot elements to this object. Plot can be viewed by using either grid.draw() or plot() function.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## Load Data
library(pscl)
data(vote92)

## Recode Variables
vote92$voteBush <- as.numeric(
  factor(vote92$vote,levels=c("Clinton","Bush")))*1 - 1
vote92$bushdis <- sqrt(vote92$bushdis)
vote92$clintondis <- sqrt(vote92$clintondis)

## Estimate Logistic Regression
fm <- formula(voteBush ~ dem + rep +
                clintondis + bushdis +
                persfinance + natlecon)
m <- glm(fm, data = vote92,
         family = binomial("logit"))

## Basic Graph
p <- plot_coef(m)

## Add Footnote
p_wfoot <- plot_footnote(p,"Votes for Ross Perot are eliminated from analysis.")
p_wfoot

gentok/estvis documentation built on April 2, 2020, 1:58 p.m.