Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot columns of a matrix on a single line graph in R

Tags:

People also ask

How do you plot a matrix graph?

Use Matrix Plot to assess the relationships between several pairs of variables at once. A matrix plot is an array of scatterplots. There are two types of matrix plots: Matrix of plots and Each Y versus each X. This type of matrix plot accepts up to 20 variables and creates a plot for every possible combination.

What is Matplot in R?

R Language Base Plotting Matplot matplot is useful for quickly plotting multiple sets of observations from the same object, particularly from a matrix, on the same graph. Here is an example of a matrix containing four sets of random draws, each with a different mean.


I created a function which reads data from a txt file to create a table, some data manipulation occurs and then the results are put into a matrix. This is a sample of the result:

          Canada     France       Germany      Italy        Japan        
1973 0.107843137 0.13583815  0.0684713376 0.19417476  0.231732777
1974 0.108407080 0.11704835  0.0596125186 0.17073171  0.116949153
1975 0.075848303 0.09567198  0.0436005626 0.16666667  0.095599393
1976 0.077922078 0.09563410  0.0363881402 0.19345238  0.081717452
1977 0.089500861 0.09108159  0.0273081925 0.12468828  0.042253521

I'm trying to figure out how I can plot this data on a graph. I want to have the years as the x - axis and the inflation rate as the y - axis. So in the end I would like one graph with lines (in different colours) for each country.

Is this possible to do?

Any help appreciated, thank you.