Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot a list of vectors with different lengths?

Tags:

list

plot

r

vector

I have a list with 9 different vectors inside. And I want plot them (dot-line) in one figure with different colors by their names. How to do that in R language?

like image 264
Fan Phill Avatar asked Aug 12 '13 05:08

Fan Phill


People also ask

Can you add two vectors of different lengths?

The individual numbers that make up a vector are called elements or components of the vector. and vector addition. Two vectors of the same size (i.e. number of elements) can be added: this adds the corresponding elements to create a new vector of the same size. You can't add two vectors of different sizes.

How do you plot two vectors?

To draw a plot from two vectors in R, where one vector represents data points along X axis, and the other vector represents data points along Y axis, call plot() function and pass the two vectors as arguments to the plot() function.


1 Answers

Using a made up example:

# example data:
dat <- list(a=1:5,b=2:7,c=3:10)
# get plotting:
plot(unlist(dat),type="n",xlim=c(1,max(sapply(dat,length))))
mapply(lines,dat,col=seq_along(dat),lty=2)
legend("topleft",names(dat),lty=2,col=seq_along(dat))

enter image description here

like image 187
thelatemail Avatar answered Sep 20 '22 15:09

thelatemail