I would like to create and plot a correlation matrix in R.
I have three vectors I create a dataFrame from. In a 2D-XY-Coordiante-System the vector "index" would be on the x-axis. And then I have two variables "var1" and "var2" (y-values) and every value with the same vector index belongs to the same index (x) value.
My tries to plot a correlation matrix faliled as I am not able to prepare my data in a proper way.
How can I prepare my data for the follwing correlation plot?
var2
900 800 700 600 500 400 300 200
900
800
700
600 filled with pairwise corrleation coefficients
var1 500
400
300
200
This is what I tried so far:
var1 <- c(10,20,3,1,10,4,21,2)
var2 <- c(1,44,1,19,19,29,1,3)
index <- c(200,300,400,500,600,700,800,900)
df <- data.frame(id = index, y1 = var1, y2=var2)
M <- cor(df)
install.packages("corrplot")
library('corrplot')
corrplot(M, method = "circle")
Thank you very much!