在 R 中向散点图添加线条
Add lines to Scatterplot in R
如何在图表中添加线条?
我关注了
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])
但是我需要所有变量的零值处的水平线和垂直线,就像这样
类似这样的方法可能有效:
##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)
请注意,此问题与 this one 非常相似。
如何在图表中添加线条? 我关注了
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])
但是我需要所有变量的零值处的水平线和垂直线,就像这样
类似这样的方法可能有效:
##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)
请注意,此问题与 this one 非常相似。