Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

Loop through a list of dataframes output plots

$
0
0

I try to make function plots or my top 20 genes. That's why I created a list of data frames, these data frames exist or different columns contain values ​​and names. One of these columns in the data frame is the gene column. My code turns the first 20 genes into function plots. But now I have the problem in some of the data frames that exist fewer than 20 genes. This causes my code to abort.

Because I want a maximum of 5 function plots per page, I cannot just define a counter.

Thank you for the input.

Example of my list or data frames listGroups

group1_2: 'data.frame': 68 obs. of 7 variables:
    ..$ p_val: num [1:68] 1.15 1.43 ...
    ..$ score: num [1:68] 15.5 27.14 ...
    ..$ gene: Factor w/ 68 levels "BRA1", "NED",...: 41 52 ...
group2_3: 'data.frame': 3 obs. of 7 variables:
    ..$ p_val: num [1:3] 1.15 1.43 ...
    ..$ score: num [1:3] 15.5 27.14 ...
    ..$ gene: Factor w/ 3 levels "BCL12", "DEF1",...: 41 52 ...

Code

groupNames <- c("cluster1_2","cluster2_3","cluster3_4","cluster4_5","cluster5_6")
for (i in 1:length(listGroups)) {
  Grouplist <- listGroups[[i]]
  genesList <- Grouplist['gene']
  lengths(geneList)
  print(groupNames[i])
  # Make Featureplots for top20 DE genes per cluster_group
  pdf(file=paste0(sampleFolder,"/Featureplots_cluster_",groupNames[i],"_",sampleName,".pdf"))
  print(FeaturePlot(object = seuratObj, features = c(as.character(genesList[1:5,]))))
  print(FeaturePlot(object = seuratObj, features = c(as.character(genesList[6:10,]))))
  print(FeaturePlot(object = seuratObj, features = c(as.character(genesList[11:15,]))))
  print(FeaturePlot(object = seuratObj, features = c(as.character(genesList[16:20,]))))
  dev.off()
}

Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>