質問

I have a matrix of 8 rows and 12 columns, and randomly distributed 10 different treatments with 9 replicates and a final treatment only with 6 replicates in the matrix. The code might be redundant, but it was the first think that came to mind and worked. I just wanted to have a scheme so that I could follow easily afterwards in the lab, to avoid mistakes:

library(ggplot2)
library(RColorBrewer)
library(reshape2)
library(scales)


replicates<-c(rep(seq(1:11),c(rep(9,10),6)));replicates
dimna<-list(c("A","B","C","D","E","F","G","H"),seq(1,12,1))
plate<-array(sample(replicates),dim=c(8,12),dimnames=dimna);plate
platec<-melt(plate);platec

guide<-ggplot(platec,aes(Var2,Var1,fill=factor(value))) + geom_tile()+geom_text(aes(fill=factor(value),label=value)) + ylim(rev(levels(platec$Var1))) + theme_bw() + theme(panel.grid.major.y=element_blank(),panel.grid.minor.y=element_blank(),panel.grid.major.x=element_blank(), axis.text.x=element_text(size=10), axis.title.y=element_blank(), axis.text.y=element_text(size=12)) + scale_fill_brewer(name="",palette="Spectral") + scale_x_continuous("",labels=c(seq(1,12,1)),breaks=c(seq(1,12,1)));guide

However, now imagine that I take measurements for the randomized matrix multiple times. And for the data processing I need to identify the treatment and replicates in the matrix. I can either have the data at the end in a columnwise:

A1  A2  A3  A4  A5  A6  A7  A8
0.12    0.2 0.124   0.14    0.4 0.18    0.46    0.47
0.13    0.21    0.6 0   0   0.58    0.4 0.2
0.15    0.248   0.58    0.4 0.2 0.248   0.2 0.18
0.18    0.46    0.47    0.3 0.21    0.2 0.21    0.58
0.1784  0.14    0.95    0.7 0.248   0.21    0.248   0.248

. . .

Or rowwise fashion:

A1  0.12    0.13    0.15    0.18    0.1784
A2  0.2 0.21    0.248   0.46    0.14
A3  0.124   0.6 0.58    0.47    0.95
A4  0.14    0   0.4 0.3 0.7
A5  0.4 0   0.2 0.21    0.248
A6  0.18    0.58    0.248   0.2 0.21
A7  0.46    0.4 0.2 0.21    0.248
A8  0.47    0.2 0.18    0.58    0.248

...

Is there a way in R in which I can relate the random matrix to the data I have collected, I have no clue on how to begin even. I'm really sorry for not having an attempt even, but I honestly wouldn't know on how to start

役に立ちましたか?

解決

I think I know what you're asking... let me know if this doesn't make sense. You need to have a design dataframe first - let's make a dummy plate:

Wells <- paste0(rep(LETTERS[1:8],each=12), rep(1:12, times = 8))
design <- data.frame(Wells, ID = sample(letters[1:10], 96, replace = TRUE))

Then when you get your result, assuming it's in a dataframe (your 'rowwise fashion?'), you can merge them together:

#dummy result data
result <- data.frame(Wells, measure = rnorm(96, 0.5))
result_whole <- merge(design, result)
head(result_whole)
#  Wells ID    measure
#1    A1  j -0.4408472
#2   A10  d -0.5852285
#3   A11  d  1.0379943
#4   A12  e  0.6917493
#5    A2  g  0.8126982
#6    A3  b  2.0218953

If you keep your designs neatly, this is very straightforward. You can then label the results (measure in this case) however you want to keep track of it all.

I hope that addresses your problem...

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top