Add lines to Scatterplot in R

淺唱寂寞╮ 提交于 2019-12-13 02:31:56

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/37008771/add-lines-to-scatterplot-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!