Hi,
I have a data for plotting as folows:
hr0 hr6 hr24 hr48 hr72 hr80
geneA 11.954941 11.811412 11.755297 11.641484 11.641685 11.462077
geneB 10.127727 10.055340 9.986837 9.937731 9.966660 9.861603
geneC 9.728326 9.686385 9.841499 9.879718 9.968936 9.973809
My intention was to have 100 plots (corresponding to each row name. i.e genes) and each plot will have with x axis( hr0 hr6 hr24 hr48 hr72 hr80) against y axis (values for each gene across columns).
I have the following code that is not working:
par(mfrow=c(3,3), ask=TRUE)
for(i in 0:99){
indx = rank(modF) == nrow(selDataMatrix_ave) - i
name = fit2$genes$geneSymbol[indx]
exprs.row = selDataMatrix_ave[indx,]
genetitle = paste(sprintf('%.30s', name),'Rank =', i+1)
plot(0, pch=1, xlim=range(0, 80), ylim=range(exprs.row),
ylab='Expression', xlab='Time', main=genetitle, col=1,lty=1)
for(j in 1:6){
#pch_value = as.character(targets$time[6*j])
points(c(0, 6, 24, 48, 72,80), exprs.row[6*j-5:6*j],
type='b', pch=1)
}
}
Help to get the code working will be appreciated. Thanks.
What do you mean by "not working", what's the error?
In addition to Ben comment, do you want these saved to a file (otherwise, they'll just flicker across your screen and you'll only see the last one)? Also, I assume that selDataMatrix_ave is the example data you posted above. So what's modF and fit2$genes$geneSymbol? BTW, I assume much of your problem is in the last for loop. Given the example data, you're going to exceed the bounds of exprs.row.
Edit: With an N of 100, are you sure you don't want a heatmap? That might be easier to interpret, depending on your goals.
On further inspection, I guess you won't exceed the bounds of exprs.row, but you're just trying to plot two elements of it at a time (including the 0th element, which doesn't exist in R) versus 6 elements. Why not just
points(c(0, 6, 24, 48, 72,80), exprs.row, type='b', pch=1)
without the inner for loop?Thanks to evryone for their comments. The solution provided by dpryan79 worked perfectly - exactly what I wanted. Your help is appreciated!!!