math
math

Reputation: 2022

Plot matrix column against a vector

Suppose I have a matrix with n columns and m rows. In my case I have a setup depending on a parameter which can take n different values. For each of these values I do some calculation, the m elements in the rows. Now I would like to plot each column against a vector (timestep), which is of course of length m. How do I do this? It should be something like plot(timestep,i-th column)? Thanks in advance!

cheers

math

Upvotes: 1

Views: 1367

Answers (1)

Jilber Urbina
Jilber Urbina

Reputation: 61204

Since you didn't provide any reproducible example I supposed you need something like this:

set.seed(001) # generating som data
Matrix <- matrix(rnorm(40,100,5), 10)
Vector <- rnorm(10, 200, 30)
par(mfrow=c(2,2))
for(i in 1:ncol(Matrix)){
  plot(Matrix[,i] ~ Vector, pch=16, cex=.65, col=i,
       main=paste('Column', i, 'of Matrix agaisnt Vector'))
}
par(mfrow=c(1,1))

Which produces...

enter image description here

Upvotes: 1

Related Questions