geom_estci: Horizontal point and line range with vertical center line.

Description Usage Arguments Value Examples

Description

Useful to visualize results from regression type analyses, as it shows the estimate, confidence interval, and optionally use the value of the p.value to highlight significant associations. A vertical line is included

Usage

1
2
3
4
5
geom_estci(mapping = NULL, data = NULL, stat = "identity",
  position = "identity", ..., height = NA, fatten = 4, na.rm = FALSE,
  show.legend = NA, center.linetype = "dashed",
  center.linecolour = "black", center.linesize = 0.5, ci.linesize = 0.5,
  inherit.aes = TRUE)

Arguments

mapping

Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

The data to be displayed in this layer. There are three options:

If NULL, the default, the data is inherited from the plot data as specified in the call to ggplot().

A data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. See fortify() for which variables will be created.

A function will be called with a single argument, the plot data. The return value must be a data.frame., and will be used as the layer data.

stat

The statistical transformation to use on the data for this layer, as a string.

position

Position adjustment, either as a string, or the result of a call to a position adjustment function.

...

other arguments passed on to layer(). These are often aesthetics, used to set an aesthetic to a fixed value, like color = "red" or size = 3. They may also be parameters to the paired geom/stat.

height

Add ends to the confidence intervals.

fatten

A multiplicative factor used to increase the size of the middle bar in geom_crossbar() and the middle point in geom_pointrange().

na.rm

If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

show.legend

logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.

center.linetype

The linetype for the center line.

center.linecolour

Line colour for the center line.

center.linesize

Line size for the center line.

ci.linesize

Line size for the confidence interval lines.

inherit.aes

If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders().

Value

Adds a ggplot2 geom layer.

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
42
43
44
library(ggplot2)
library(broom)

fit <- lm(Fertility ~ 0 + Catholic + Agriculture + Examination +
Education + Infant.Mortality, data = swiss)
fit <- tidy(fit, conf.int = TRUE)
fit <- transform(fit, model = "non-log", p.value = discrete_pvalue(fit$p.value))

p <- ggplot(fit, aes(x = estimate, y = term, xmin = conf.low, xmax = conf.high))
p + geom_estci()

p + geom_estci(aes(xintercept = 1.1), center.linecolour = "red")
p + geom_estci(aes(size = p.value), linetype = "dotted")
p + geom_estci(aes(colour = p.value, size = p.value), linetype = "dotted")
p + geom_estci(aes(colour = p.value, size = p.value), linetype = "dotted") +
  scale_colour_grey(start = 0.75, end = 0)
p + geom_estci(aes(size = p.value, alpha = p.value), linetype = "dotted")
p + geom_estci(aes(size = p.value, alpha = p.value, colour = p.value))
p + geom_estci(aes(alpha = p.value), linetype = "dashed",
center.linetype = "solid")

p + geom_estci(aes(alpha = p.value, xintercept = 1),
colour = "blue", linetype = "dashed", center.linetype = "solid")

p + geom_estci(aes(alpha = p.value, xintercept = 1), center.linesize = 1.5)
p + geom_estci(center.linesize = 0.25, height = 1, fatten = 2)
p + geom_estci(center.linesize = 2, height = 0.5, fatten = 8)
p + geom_estci(ci.linesize = 3)
p + geom_estci(aes(size = p.value, colour = p.value), fatten = 2)

fit_log <- lm(log(Fertility) ~ 0 + Catholic + Agriculture + Examination +
    Education + Infant.Mortality, data = swiss)
fit_log <- tidy(fit_log, conf.int = TRUE)
fit_log <- transform(fit_log, model = "log",
    p.value = discrete_pvalue(fit_log$p.value))
two_fits <- rbind(fit, fit_log)

p <- ggplot(two_fits, aes(x = estimate, y = term, xmin = conf.low, xmax = conf.high))
# It might be possible to show groups with 'dodging', but it is currently in development.
# p + geom_estci(aes(group = model, colour = model), position = position_dodge(width = 0.3))
p + geom_estci()

p <- ggplot(two_fits, aes(x = estimate, y = term, xmin = conf.low, xmax = conf.high))
p + geom_estci() + facet_grid(~ model)

lwjohnst86/ggepi documentation built on May 13, 2019, 3:07 a.m.