I would like to visualize covariance in R. I found a promising example here:
https://evangelinereynolds.netlify.app/post/geometric-covariance/
Obviously it can be done in R and ggplot2
.
I can create a scatterplot and add the two means of data.
x=c(4,13,19,25,29)
y=c(10,12,28,32,38)
data <- data.frame(x, y)
ggplot(aes(x=x, y=y), data=data) +
geom_point(size=3) +
labs(title="Distribution of x and y around their means") +
theme_bw() +
geom_vline(xintercept=mean(x), size=1.5, color="red") +
geom_hline(yintercept=mean(y), size=1.5, color="red")
How do I add arrows from each data point to the respective means and color the squares?