I wrote some code that reads some data from a text file, turns it into a matrix and plots each column of the matrix in a separate graph:
#Read data from txt file into table and convert table into matrix
excMatrix = as.matrix(read.table("/Users/Kane/Desktop/Gujarati/Table 1.3.txt", header = TRUE, row.names = 1))
#Plotting function
excPlot = function(x) {
plot(row.names(excMatrix),x,xlab = "Year", ylab = "Exchange rate (US)", type = "l")
legend("topright", legend = "something to get column names for legend", pch = 1, col = 1:2, bty = "n")
}
#Plot exchange rates from various countries on seperate graphs
apply(excMatrix, 2, excPlot)
When I run this it makes the correct graphs but I can't figure out how to get the name of the country in the legend i.e. each graph is data for a separate country who's names are the columns of the matrix.
Hopefully that makes sense, any help appreciated.