Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add lines to Scatterplot in R

Tags:

r

scatter-plot

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

Result

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

like image 658
Julia Lapina Avatar asked Jan 17 '26 19:01

Julia Lapina


1 Answers

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)

Result

Note that this question is very similar to this one.

like image 193
bouncyball Avatar answered Jan 21 '26 07:01

bouncyball