View source: R/bruceR-stats_5_advance.R
ccf_plot | R Documentation |
Plot the results of cross-correlation analysis using ggplot2
(rather than R base plot) for more flexible modification of the plot.
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"
)
formula |
Model formula like |
data |
Data frame. |
lag.max |
Maximum time lag. Defaults to |
sig.level |
Significance level. Defaults to |
xbreaks |
X-axis breaks. |
ybreaks |
Y-axis breaks. |
ylim |
Y-axis limits. Defaults to |
alpha.ns |
Color transparency (opacity: 0~1) for non-significant values.
Defaults to |
pos.color |
Color for positive values. Defaults to |
neg.color |
Color for negative values. Defaults to |
ci.color |
Color for upper and lower bounds of significant values.
Defaults to |
title |
Plot title. Defaults to an illustration of the formula. |
subtitle |
Plot subtitle. |
xlab |
X-axis title. Defaults to |
ylab |
Y-axis title. Defaults to |
Significant correlations with negative time lags suggest shifts in a predictor precede shifts in an outcome.
A gg
object, which you can further modify using
ggplot2
syntax and save using ggsave()
.
granger_test
# resemble the default plot output by `ccf()`
p1 = ccf_plot(chicken ~ egg, data=lmtest::ChickEgg)
p1
# 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")
p2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.