for this data:
big = runif(60);mangum = runif(61:120)
df = data.frame(big, mangum)
df_x <- eval(substitute(big), df)
df_y <- eval(substitute(mangum), df)
ccf.object <- ccf(df_x, df_y, plot = FALSE)
output_table <- cbind(lag = ccf.object$lag,
x.corr = ccf.object$acf) %>%
as_tibble() %>% mutate(cat = ifelse(x.corr > 0, "green", "red"))
output_table %>% ggplot(aes(x = lag, y = x.corr)) +
geom_bar(stat = "identity", aes(fill = cat))
[![enter image description here][1]][1]
How can add a smmothing curve above or below the bars like in the picture( bold line blue).
- geom_smooth() does not do what I need.
>Solution :
You could use stat_xspline from ggalt:
output_table %>%
ggplot(aes(x = lag, y = x.corr)) +
geom_col(aes(fill = paste0(cat, 3), color = after_scale(alpha(fill, 1))),
alpha = 0.5) +
geom_hline(yintercept = 0) +
ggalt::stat_xspline(spline_shape = -0.5, color = 'blue', linewidth = 1) +
scale_fill_identity() +
theme_minimal()
