Hola Soy Leticia, quería hacer una consulta al grupo a ver si me podéis ayudar.
Tengo unos datos de proteínas, el data frame es: 5 columnas iniciales que tienen información sobre las proteínas y después las columnas con las intensidades, de las cuales no se cuantas condiciones tienen ni cuántas réplicas por condición. Estoy intentando hacer un cálculo del coeficiente de variación por grupo y representarlo en con boxplots. Para poder hacer este plot, la mejor opción que he encontrado es crear una lista por grupo y calcular el coeficiente de variación por lista, ejemplo: tres condiciones == tres listas == 3 CV == 3 box in the plot. Mi problema y donde necesito ayuda es que no consigo hacer un código general para poder hacer las listas de forma automática, y esta parte es el cuello de botella que siempre necesita que sea hardcoded (en negrita) abajo. He puesto los pasos que tengo, 1) pedir numero de replicas y condiciones 2) renombrar las intensidades en base a lo anterior 3) hacer las listas ************ (AYUDA) El codigo que tengo hasta ahora es: ######### 1 ## Esta parte para introducir el numero de replicas y condiciones, que varia segun el experimento x = readline("Enter number of replicates: ") print(paste("Number of replicates:", x )) y = readline("How many conditions? ") print(paste("You have ", y , "conditions") ########################### Esta parte para renombrar las intensidades usando x e y ###### 2 for (i in 1:y){ varnames[i] <- c(rep(paste0("gp_", i), y)) } varnames Group <- factor(varnames) nu.Norm <- select_if(Norm, is.numeric) #this part will change the columns names, do we want that? names(nu.Norm) <- paste0(rep(varnames, each=x), "_", 1:x) nu.Norm ############################## Crear listas para el boxplot ###### 3 *listgp <- list(Norm[,6:(as.numeric(x)+5)], Norm[,(as.numeric(x)+5):(as.numeric(x)*2+5)], Norm[,(as.numeric(x)*2+5):(as.numeric(x)*3+5)])* OR f *or (c in colnames(nu.Norm)){ dat1 <- nu.Norm %>% select( contains("gp_1_")) dat2 <- nu.Norm %>% select( contains("gp_2_")) dat3 <- nu.Norm %>% select( contains("gp_3_"))}list.gp <http://list.gp> <- list(dat1, dat2, dat3)* cv.df <- lapply(list.gp, function(x){(apply(x,1,sd)/rowMeans(x))*100}) cvdf <-as.data.frame(do.call("cbind", cv.df)) colnames(cvdf)<-c(varnames) ###### crear la figura palette<-rep(c(randomColor(y, luminosity="random")), times=c(1,1,1)) cvdf_melt<-reshape2::melt(cvdf) g5 <-ggplot( cvdf_melt, aes(x=variable, y=value))+geom_boxplot(color="black",fill=palette, alpha=0.8)+##, fill="Experiment" scale_y_continuous(limits=c(0,100), breaks=seq(0,100, by=10))+ theme_bw()+ theme(panel.grid.major = element_line(colour = "gray85"), panel.grid.minor = element_line(colour = "gray85"), axis.text.x = element_text(color = "black", size = 12,angle=45, hjust=1,vjust=1), axis.text.y= element_text(color = "black", size = 12,angle=0, hjust=0.5,vjust=0.5), axis.title.x=element_text(color = "black", size = 15,angle=0, hjust=0.5,vjust=0.5), axis.title.y=element_text(color = "black", size = 15,angle=90, hjust=0.5,vjust=0.5), axis.ticks.length = unit(5, "pt"), axis.ticks = element_line(size = 1), legend.position="none", title =element_text(size=12))+ labs(x="", y = "CV(%)", title="Coefficient of variation") g5 GRACIAS! [[alternative HTML version deleted]] _______________________________________________ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es