[英]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. 它将df中的每个变量与彼此完全相符。
But I want to add 45 degree line(where x=y), in each and every sub plot. 但我想在每个子图中添加45度线(其中x = y)。 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].
我也尝试过循环但是由于“空间约束”它不会发生[实际上我在df中有5个变量]。 Please help.
请帮忙。
Thanks 谢谢
plot(df)
calls pairs
to plot data.frames. plot(df)
调用pairs
来绘制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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.