Overplotting in Base R


Points Function

plot(1:10, type = 'o')
points(1:10, rnorm(10,5), col = 'firebrick')


Lines Function

a <- c(5,3,6,1,5,10)
b <- c(1,3,5,6,7,8)

plot(a, type = 'o')
lines(b, type = 'o', col = 'firebrick')


Par Function

plot(1:10, type = 'o')
par(new = T)
plot(1:10, rnorm(10,5), type = 'o',
     xlab = '', ylab = '', axes = F,
     col = 'firebrick')


abline Function

Horizontal and vertical line:

plot(1:10)

abline(h = 5, col = 'firebrick')
abline(v = 5, col = 'firebrick')


Coefficient based line:

plot(1:10)
abline(0,1, col = 'firebrick')


That’s all for now!

- Fisher



Comments