Julia Lapina
Julia Lapina

Reputation: 35

Add lines to Scatterplot in 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])

Result

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

Upvotes: 3

Views: 1939

Answers (1)

bouncyball
bouncyball

Reputation: 10761

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.

Upvotes: 2

Related Questions