I want to create arrows between two correlation matrices. Here's the code to create the matrices
library(gridExtra)
library(ggplot2)
X <- data.frame("x1" = rnorm(100, 0, 1),
"x2" = rnorm(100, 0, 1),
"x3" = rnorm(100, 0, 1))
plotCors <- function(df)
{
ggplot(df,
aes(x = X1,
y = X2, fill = value)) +
geom_tile()
}
plots_list <- map(list(melt(cor(X)), melt(cor(X))), plotCors)
grid.arrange(plots_list[[1]], plots_list[[2]] +
scale_x_discrete(limits = c("x1", "x3", "x2")) +
scale_y_discrete(limits = c("x1", "x3", "x2")),
nrow = 1)
Is it possible to automatically create such arrows as below?

One option would be to create your arrows as a third plot which could then be combined with the correlation plots, where for convenience I use
patchworkinstead ofgrid.arrange: