Hi r-help-boun...@r-project.org napsal dne 28.05.2009 16:21:01:
> > I want to plot data such that the 3 time points(a,b,c) lie on the X-axis > and > > the values of these times points are on Y-axis for n samples (e.g.100). > > > > So, I have an object x, dim 100 4, it is a dataframe (when checked the > > class) > > x = > > name a b c > > 1 0.11 1.11 0.86 > > 2 . . . > > 3 . . . > > . > > . > > . > > 100 > > > > so when i say: > > > > > plot(1:3, x[,2:4], type="l") ----- I get the error below > > > > Error in xy.coords(x, y, xlabel, ylabel, log) : > > (list) object cannot be coerced to type 'double' > > > > However if I do: > > > plot(1:3, x[1,2:4], type="l") ------ It works for the 1st row, and > each > > > individual row BUT NOT ALL ROWS > > > > Please could someone explain what is happening here? > > > > I wonder if I need to use 'lines' for the remaining, BUT I have another > > dataset y with same dimensions as x, which I want to plot on the same > > graph/plot to see the difference between x and y. > > Your data looks like this: > x <- data.frame(name=sample(letters, 10), a=runif(10), b=rnorm(10), > c=rlnorm(10)) > > The problem is that the subset x[,2:4] is also a data frame, not a matrix. > class(x[,2:4]) #[1] "data.frame" > > The simplest thing is probably to use lines, as you say. > row <- seq_len(nrow(x)) > xx <- x[,2:4] > plot(row, xx$a, ylim=range(xx), type="l") > lines(row, xx$b, col="blue") > lines(row, xx$c, col="green") Maybe also matplot is worth try matplot(1:3,t(x[,2:4])) regards Petr > > Regards, > Richie. > > Mathematical Sciences Unit > HSL > > > ------------------------------------------------------------------------ > ATTENTION: > > This message contains privileged and confidential inform...{{dropped:20}} > > ______________________________________________ > 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. ______________________________________________ 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.