45 degree line in Plot function in R

I have the following data:

df <- data.frame(X=rnorm(10,0,1), Y=rnorm(10,0,1), Z=rnorm(10,0,1)) 

I need to map each variable against each other, so I used

 plot(df) 

He built each variable inside df against each other exactly what was required.

But I want to add a 45 degree line (where x = y) in each subtitle. I want to know how to do this? I also tried a loop, but due to โ€œspace limitationsโ€ this could not happen (in fact, I have 5 variables inside df]. Please help.

thanks

+5
source share
1 answer

plot(df) calls pairs to build data.frames. So, using this answer , we can try:

 my_line <- function(x,y,...){ points(x,y,...) segments(min(x), min(y), max(x), max(y),...) } pairs(df, lower.panel = my_line, upper.panel = my_line) 

enter image description here

+7
source

Source: https://habr.com/ru/post/1235780/


All Articles