I have data like this :
df <- data.frame(X=rnorm(10,0,1), Y=rnorm(10,0,1), Z=rnorm(10,0,1))
I need to plot each variables against each other, so I used
plot(df)
It plotted each variable within the df against the each other exactly what is required.
But I want to add 45 degree line(where x=y), in each and every sub plot. I want to know how it can be done ? I also tried through loop but due to "space constraint" it could not happen[in reality i have 5 variables within the df]. Please help.
Thanks
答案 0 :(得分:7)
plot(df)
调用pairs
来绘制data.frames。因此,使用this answer,我们可以尝试:
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)