# How to make two different matrix's appear on the same graph in R

mat1=matrix(nrow=31,ncol=2)
mat1[1,1]=1976
mat1[1,2]=1
mat1[2,1]=1983
mat1[2,2]=2
mat1[3,1]=1988
mat1[3,2]=1
mat1[4,1]=1989
mat1[4,2]=2
mat1[5,1]=1990
mat1[5,2]=4
mat1[6,1]=1992
mat1[6,2]=2
mat1[7,1]=1993
mat1[7,2]=1
mat1[8,1]=1994
mat1[8,2]=1
mat1[9,1]=1996
mat1[9,2]=1
mat1[10,1]=1997
mat1[10,2]=2
mat1[11,1]=1998
mat1[11,2]=3
mat1[12,1]=1999
mat1[12,2]=1
mat1[13,1]=2001
mat1[13,2]=2
mat1[14,1]=2002
mat1[14,2]=4
mat1[15,1]=2003
mat1[15,2]=2
mat1[16,1]=2004
mat1[16,2]=1
mat1[17,1]=2005
mat1[17,2]=1
mat1[18,1]=2006
mat1[18,2]=7
mat1[19,1]=2007
mat1[19,2]=7
mat1[20,1]=2008
mat1[20,2]=5
mat1[21,1]=2009
mat1[21,2]=5
mat1[22,1]=2010
mat1[22,2]=4
mat1[23,1]=2011
mat1[23,2]=5
mat1[24,1]=2012
mat1[24,2]=7
mat1[25,1]=2013
mat1[25,2]=3
mat1[26,1]=2014
mat1[26,2]=1
mat1[27,1]=2015
mat1[27,2]=8
mat1[28,1]=2016
mat1[28,2]=5
mat1[29,1]=2017
mat1[29,2]=10
mat1[30,1]=2018
mat1[30,2]=1
mat1[31,1]=2019
mat1[31,2]=18

mat2=matrix(nrow=21,ncol=2)
mat2[1,1]=1980
mat2[1,2]=1
mat2[2,1]=1982
mat2[2,2]=1
mat2[3,1]=1984
mat2[3,2]=1
mat2[4,1]=1985
mat2[4,2]=1
mat2[5,1]=1987
mat2[5,2]=1
mat2[6,1]=1991
mat2[6,2]=1
mat2[7,1]=1992
mat2[7,2]=2
mat2[8,1]=1994
mat2[8,2]=1
mat2[9,1]=1995
mat2[9,2]=2
mat2[10,1]=1996
mat2[10,2]=1
mat2[11,1]=1999
mat2[11,2]=2
mat2[12,1]=2001
mat2[12,2]=1
mat2[13,1]=2002
mat2[13,2]=2
mat2[14,1]=2003
mat2[14,2]=2
mat2[15,1]=2004
mat2[15,2]=1
mat2[16,1]=2006
mat2[16,2]=1
mat2[17,1]=2007
mat2[17,2]=1
mat2[18,1]=2013
mat2[18,2]=1
mat2[19,1]=2016
mat2[19,2]=1
mat2[20,1]=2017
mat2[20,2]=1
mat2[21,1]=2019
mat2[21,2]=1

plot(mat1,mat2,type="l",ylab = expression("Number of shark bites within the year"),xlab = expression("year the shark bite occurred"), main = "annual frequency of shark bites on bottlenose dolphins")

This code will produce a plot with two lines, mat1 in black and mat2 in red. Is that the sort of thing you are looking for?

``````plot(mat1[,1], mat1[,2], type = "l")
lines(mat2[,1], mat2[, 2], col = "red")
``````

Thank you! You dont know how long I struggled with this code.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.