Ole Petersen
Ole Petersen

Reputation: 680

Several plots in one plot

In R I want to plot say these vectors in one plot.

a <- c(1,2,5,4)
b <- c(10,2,3,4)
d <- c(5,4,6,8)

To plot these I type

plot(a, col="blue")
points(b, col="green")
points(d, col="orange")

Now I get not all points and that is confusing. The plot is simply not 'big' enough to capture all points. Is there a way to solve this ?

Upvotes: 0

Views: 183

Answers (1)

etienne
etienne

Reputation: 3678

You can use matplot :

m<-cbind(a,b,d)
matplot(m,type='l',col=c('blue','green','orange'),lty=1,lwd=1)

enter image description here

An other option is to specify the limits of the y-axis :

plot(a, col="blue",ylim=c(0,10))
points(b, col="green")
points(d, col="orange")

enter image description here

You can of course change the type of lines, width, labels, ... for both options.

Upvotes: 4

Related Questions