[R] PLot a matrix

David L Carlson dcarlson at tamu.edu
Sun May 6 21:30:50 CEST 2012


Assuming Windows OS with the data you attached copied to the clipboard:

TSdata <- read.table("clipboard", header=FALSE, sep="", na.strings="NA", 
  dec=".", strip.white=TRUE)

Then just

matplot(TSdata, type="l")

But you will probably want to select your own colors, line types, and add a
legend:

?matplot
?legend

If you want separate plots in one plot window:

par(mfrow=c(2, 3))
for (i in 1:5) {
   plot(TSdata[,i], ylab=paste("V", i, sep=""), type="l")
}

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Gabor Grothendieck
> Sent: Sunday, May 06, 2012 12:16 PM
> To: Trying To learn again
> Cc: r-help at r-project.org
> Subject: Re: [R] PLot a matrix
> 
> On Sun, May 6, 2012 at 11:39 AM, Trying To learn again
> <tryingtolearnagain at gmail.com> wrote:
> > Hi,
> >
> > I want to plot this matrix (I attach the data), it is suposed that
> each
> > column is a different time series.
> >
> > If I do
> >
> > g<-read.table("dataADF.txt", header=F)
> >
> > and
> >
> > plot(g[,1],type="l")
> >
> > it  plots the first column plot if I want in a unique graph each
> colums of
> > dataA, all in one. How should I proceed?There is a direct pre-defined
> code?
> >
> > And  If I wanted a plot by each column?
> >
> 
> 
> Try this:
> 
> library(zoo)
> URL <- "http://r.789695.n4.nabble.com/attachment/4613171/0/dataA.txt"
> z <- read.zoo(URL, index = 0)
> 
> plot(z) # multi-panel
> plot(z, screen = 1, col = 1:5) # single panel
> 
> See ?plot.zoo for more details.
> 
> 
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list