ccf_plot: Cross-correlation analysis.

Description Usage Arguments Details Value See Also Examples

View source: R/bruceR_stats_05_advance.R

Description

Plot the results of cross-correlation analysis using ggplot2 (rather than R base plot) for more flexible modification of the plot.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
ccf_plot(
  formula,
  data,
  lag.max = 30,
  sig.level = 0.05,
  xbreaks = seq(-100, 100, 10),
  ybreaks = seq(-1, 1, 0.2),
  ylim = NULL,
  alpha.ns = 1,
  pos.color = "black",
  neg.color = "black",
  ci.color = "blue",
  title = NULL,
  subtitle = NULL,
  xlab = "Lag",
  ylab = "Cross-Correlation"
)

Arguments

formula

Model formula like y ~ x.

data

Data frame.

lag.max

Maximum time lag. Default is 30.

sig.level

Significance level. Default is 0.05.

xbreaks

X-axis breaks.

ybreaks

Y-axis breaks.

ylim

Y-axis limits. Default is NULL to automatically estimate.

alpha.ns

Color transparency (opacity: 0~1) for non-significant values. Default is 1 for no transparency (i.e., opaque color).

pos.color

Color for positive values. Default is "black".

neg.color

Color for negative values. Default is "black".

ci.color

Color for upper and lower bounds of significant values. Default is "blue".

title

Plot title. Default is an illustration of the formula.

subtitle

Plot subtitle.

xlab

X-axis title. Default is "Lag".

ylab

Y-axis title. Default is "Cross-Correlation".

Details

Significant correlations with negative time lags suggest shifts in a predictor precede shifts in an outcome.

Value

A gg object, which you can further modify using ggplot2 syntax and save using ggsave().

See Also

granger_test

Examples

1
2
3
4
5
6
7
8
# resemble the default plot output by `ccf()`
p1=ccf_plot(chicken ~ egg, data=lmtest::ChickEgg)

# a more colorful plot
p2=ccf_plot(chicken ~ egg, data=lmtest::ChickEgg, alpha.ns=0.3,
            pos.color="#CD201F",
            neg.color="#21759B",
            ci.color="black")

bruceR documentation built on June 22, 2021, 1:06 a.m.