gpt4 book ai didi

r - 在 R 中向散点图添加线条

转载 作者:行者123 更新时间:2023-12-04 16:47:50 25 4
gpt4 key购买 nike

如何在图表中添加线条?我做了以下

dat <- data.frame(xvar = 1:20 - rnorm(20,sd=10),
yvar = 1:20 - rnorm(20,sd=10),
zvar = 1:20 - rnorm(20,sd=10))
plot(dat[,1:3])

Result

但是我需要所有变量的零值处的水平线和垂直线,就像这样 Required

最佳答案

这样的事情可能会起作用:

##define a function to use in pairs
plotfun <- function(x,y,...){
points(x,y,...) #plot them
abline(h = 0) #horizontal line
abline(v = 0) #vertical line
}
pairs(dat, upper.panel = plotfun)

Result

请注意,此问题与 this one 非常相似.

关于r - 在 R 中向散点图添加线条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37008771/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com