简体   繁体   中英

45 degree line in Plot function in R

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

plot(df) calls pairs to plot 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)

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM