在 R 中向散点图添加线条 [英] Add lines to Scatterplot in R

查看:91
本文介绍了在 R 中向散点图添加线条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How to add lines to the chart? I did following

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])

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

But I need horizontal and vertical lines at the value zero of all variables, like this

推荐答案

这样的事情可能会奏效:

Something like this might work:

##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)

请注意,这个问题非常类似于 这个.

Note that this question is very similar to this one.

这篇关于在 R 中向散点图添加线条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆