graph - Iteratively print plots in R -


i have series of vectors , want print them iteratively (so far did hardcoding want avoid doing 1 one again). names of variables hold names of vectors stored in "genes" (char), while can see variables using ls() (ok nothing new far) each vector of variable length , want print index (x axis) against value (y axis). data i'm downloading come tcga database , can accessible r package. have far is:

library(cgdsr)  #create object  mycgds = cgds("http://www.cbioportal.org/public-portal/") genes <- c("agpat1", "cdipt", "cds1", "cel", "cept1", "dgka", "lcat", "lclat1", "lpcat3", "lpin1", "lpl", "mogat3", "pemt", "pisd", "pla2g4b", "pld1","ptdss1", "ptdss2", "atx", "pla2") # list of gene names  # z score these genes kidney cancer data <- getprofiledata(mycgds, genes, "kirc_tcga_pub_rna_seq_v2_mrna_median_zscores", "kirc_tcga_pub_3way_complete" )  data <- t(data)  #set z-value cutoff (equivalent p<0.05) <- -1.96 j <- 1.96  # select samples have values lower , higher j  agpat1 <- data[1,which(data[1,] < | data[1,] > j)] cdipt <- data[2,which(data[2,] < | data[2,] > j)] cds1 <- data[3,which(data[3,] < | data[3,] > j)] cel <- data[4,which(data[4,] < | data[4,] > j)] cept1 <- data[5,which(data[5,] < | data[5,] > j)] dgka <- data[6,which(data[6,] < | data[6,] > j)] lcat <- data[7,which(data[7,] < | data[7,] > j)] lclat1 <- data[8,which(data[8,] < | data[8,] > j)] lpcat3 <- data[9,which(data[9,] < | data[9,] > j)] lpin1 <- data[10,which(data[10,] < | data[10,] > j)] lpl <- data[11,which(data[11,] < | data[11,] > j)] mogat3 <- data[12,which(data[12,] < | data[12,] > j)] pemt <- data[13,which(data[13,] < | data[13,] > j)] pisd <- data[14,which(data[14,] < | data[14,] > j)] pla2g4b <- data[15,which(data[15,] < | data[15,] > j)] pld1 <- data[16,which(data[16,] < | data[16,] > j)] ptdss1 <- data[17,which(data[17,] < | data[17,] > j)] ptdss2 <- data[18,which(data[18,] < | data[18,] > j)] atx <- data[19,which(data[19,] < | data[19,] > j)] pla2 <- data[20,which(data[20,] < | data[20,] > j)]  #setup page 18graphs, not 20 cause there no values last 2  par(mfrow= c(3,6))      color <- function(x){       ifelse(x > 1.96, "red", "green")     }      (k in seq(1,length(ls()),1)) #iterate through ls()       for(z in seq(1, length(genes),1)) #iterate through list of genes         if(genes[z] == ls()[k]) #if match print them out           plot(ls()[k], pch=15, col=color(ls()[k]), main =genes[z], ylim=c(-3,30)) 

the "color" function assign color based on value

however, can't work. not print graphs few , not apply right colors.

thanks :)

ok, easy. missied get(). try

for (k in seq(1,length(ls()),1)) #iterate through ls()   for(z in seq(1, length(genes),1)) #iterate through list of genes     if(genes[z] == ls()[k]) #if match print them out       plot(get(ls()[k]), pch=15, col=color(ls()[k]), main =genes[z], ylim=c(-3,30)) 

not related exact question here clearer (and faster) version of loop

for (k in 1:length(ls())) #iterate through ls()     if(any(genefound <- genes == ls()[k])) #if match print them out       plot(get(ls()[k]), pch=15, col=color(ls()[k]), main =genes[genefound],            ylim=c(-3,30)) 

edit:

after changing col=color(ls()[k]) in col=color(get(ls()[k])) got this:

enter image description here

and error:

error in plot.window(...) : need finite 'xlim' values in addition: warning messages: 1: in min(x) : no non-missing arguments min; returning inf 2: in max(x) : no non-missing arguments max; returning -inf 

due 2 missing vectors said. expect?


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -