Hi Dennis and Gabor, Thanks a lot for the useful suggestions! Cheers!! Albert-Jan
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In the face of ambiguity, refuse the temptation to guess. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- On Sun, 1/3/10, Gabor Grothendieck <ggrothendi...@gmail.com> wrote: From: Gabor Grothendieck <ggrothendi...@gmail.com> Subject: Re: [R] plot question To: "Albert-Jan Roskam" <fo...@yahoo.com> Cc: r-help@r-project.org Date: Sunday, January 3, 2010, 10:10 PM I gather that each row defines one series, right? In that case try this: Lines <- "date sober no vm nm va na vs 20091229 NA 6.8 NA 2.7 11.7 2.7 6.2 20091230 NA 6.8 NA 2.7 11.7 2.7 6.2 20091231 NA 6.8 NA 2.7 11.7 2.7 6.2" # g <- read.table("myfile.txt", header = TRUE) g <- read.table(textConnection(Lines), header = TRUE) # create zoo object with each series in a column and plot it # na.approx fills in NAs with interpolated values library(zoo) z <- zoo(t(g[, -1])) colnames(z) <- g[,1] plot(na.approx(z), type = "b", main = "Glucose") If you want the series surperimposed on one panel then add the screens=1 argument to the last line. On Sun, Jan 3, 2010 at 3:24 PM, Albert-Jan Roskam <fo...@yahoo.com> wrote: > Hi, > > I am new to R so forgive me if the following query is somewhat simple. I > have a small tab-separated file with n records of glucose values, one record > per day, seven measurements per day. It looks like this: > > date sober no vm nm va na vs > 20091229 NA 6.8 NA 2.7 11.7 2.7 6.2 > > I'd like to make a graph on which the glucose day curves are plotted > separately for each day. I'm sure I'll be able to make it pretty (such as > labelling, etc), but yesterday I've been struggling just a bit too long to > get the basics right. Here's what I've got till sofar: > > file = "d:/temp/glucose.tab" > glucose <- read.table(file, header=TRUE, sep="\t", row.names="datum") # > # Not sure if I got the row.names correct, I may need to use as.character (I > believe I did use #that in the interactive session). > attach(glucose) > summary(glucose) > > ncol <- length(names(glucose)) > xrange <- range(1, ncol) > yrange <- range(0, max(!is.na(glucose[1:ncol]))) > > nrecs <- nrow(glucose) > colors <- rainbow(nrecs) > linetype <- c(1:nrecs) > plot(xrange, yrange, type="n", xlab="Measurement moment", ylab="Glucose > (mmol/liter)") > for (i in 1: nrecs) { > daily_values <- glucose[i,] > lines(daily_values, type="b", lwd=1.5, lty=linetype[i], col=colors[i]) > } > > So I want to loop over the file and add the plot lines one by one (day by > day), but it seems that something's not yet right because nothing appears on > the graph. Can anybody give me some pointers? Thank you in advance > > > Cheers!! > > Albert-Jan > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > In the face of ambiguity, refuse the temptation to guess. > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help@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. > > [[alternative HTML version deleted]]
______________________________________________ R-help@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.