Without your data, I have to create a toy, called mat , with 5 rows and 10 columns filled with letters[1:7] .
set.seed(0); mat <- matrix(sample(letters[1:7], 5 * 10, TRUE), nrow = 5) # [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] #[1,] "g" "b" "a" "f" "f" "b" "c" "f" "c" "d" #[2,] "b" "g" "b" "d" "g" "c" "d" "e" "f" "f" #[3,] "c" "g" "b" "f" "b" "a" "e" "f" "e" "a" #[4,] "e" "e" "e" "g" "e" "c" "d" "a" "f" "d" #[5,] "g" "e" "c" "c" "a" "g" "b" "f" "d" "f"
Basically you need to first represent the character matrix mat as integers.
#
Then you simply draw (whole or multiple rows) of this matrix using matplot . Disable the y axis first, and then add it later using the axis so you can adjust the labels of the axes.
## this plots the whole matrix matplot(t(mat_int), yaxt = "n", type = "l", xlab = "time", ylab = "category") axis(2, seq_along(lev), labels = lev) ## this plots 1st and 5th rows matplot(t(mat_int)[, c(1,5)], yaxt = "n", type = "l", xlab = "time", ylab = "category") axis(2, seq_along(lev), labels = lev)
Graph of the selected two lines:
