r - A better way to plot lots of lines (in ggplot perhaps)? -


using r 3.0.2, have dataframe looks like

head()          0     5    10    15    30    60   120   180   240 ykl134c  0.08 -0.03 -0.74 -0.92 -0.80 -0.56 -0.54 -0.42 -0.48 ymr056c -0.33 -0.26 -0.56 -0.58 -0.97 -1.47 -1.31 -1.53 -1.55 ybr085w  0.55  3.33  4.11  3.47  2.16  2.19  2.01  2.09  1.55 yjr155w -0.44 -0.92 -0.27  0.75  0.28  0.45  0.45  0.38  0.51 ynl331c  0.42  0.01 -0.05  0.23  0.19  0.43  0.73  0.95  0.86 yol165c -0.49 -0.46 -0.25  0.03 -0.26 -0.16 -0.12 -0.37 -0.34 

where row.names() variable names, names() measurement times, , values measurements. it's several thousand rows deep. let's call tmp.

i want sanity check of plotting every variable time versus value line-plot on 1 plot. what's better way naively plotting each line plot() , lines():

timez <- names(tmp) plot(x=timez, y=tmp[1,], type="l", ylim=c(-5,5)) (i in 2:length(tmp[,1])) {     lines(x=timez,y=tmp[i,]) } 

the above crude answer enough, i'm looking way right. had concusion recently, sorry if i'm missing obvious. i've been doing lot.

could transposing data.frame it's each timepoint observed across several thousand variables? or melt()-ing data.frame in meaningful way? there someway of handling in ggplot using aggregate()s of data.frames or something? isn't right way this, it?

at loss.

i prefer ggplot2 of plotting needs. assuming i've understood correctly, can put data in long format reshape2 , use ggplot2 plot of lines on same plot:

library(reshape2) df2<-melt(df,id.var="var") names(df2)<-c("var","time","value") df2$time<-as.numeric(substring(df2$time,2))  library(ggplot2) ggplot(df2,aes(x=time,y=value,colour=var))+geom_line() 

enter image description here


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -