0

I figured out how to plot graphs in loop with the print but it is printing 2 plots per line and getting cutoff. Even when I add cat("\n") it still has 2 plots per line. How to print 1 plot per line?

for (clust in intersecting.001.2.unlog) {
  ex <- row.names(map[map$transcript_cluster_id == clust, ])

  Clotrimazole.exon <- Clotrimazole.e[ex,]
  Clotrimazole.gene <- Clotrimazole.g[as.character(clust),]
  Chlorhexidine.exon <- Chlorhexidine.e[ex,]
  Chlorhexidine.gene <- Chlorhexidine.g[as.character(clust),]
  
  # https://stackoverflow.com/questions/11956520/r-knitr-markdown-output-plots-within-for-loop
  print(plot.exons(exonx.drug1=Clotrimazole.exon, 
             genex.drug1=as.numeric(Clotrimazole.gene), 
             rx.drug1=Clotrimazole.r,
             exonx.drug2=Chlorhexidine.exon, 
             genex.drug2=as.numeric(Chlorhexidine.gene), 
             rx.drug2=Chlorhexidine.r,
             ti=clust))
}

for (clust in intersecting.001.2.unlog) {
  ex <- row.names(map[map$transcript_cluster_id == clust, ])

  Clotrimazole.exon <- Clotrimazole.e[ex,]
  Clotrimazole.gene <- Clotrimazole.g[as.character(clust),]
  Chlorhexidine.exon <- Chlorhexidine.e[ex,]
  Chlorhexidine.gene <- Chlorhexidine.g[as.character(clust),]
  
  # https://stackoverflow.com/questions/11956520/r-knitr-markdown-output-plots-within-for-loop
  print(plot.exons(exonx.drug1=Clotrimazole.exon, 
             genex.drug1=as.numeric(Clotrimazole.gene), 
             rx.drug1=Clotrimazole.r,
             exonx.drug2=Chlorhexidine.exon, 
             genex.drug2=as.numeric(Chlorhexidine.gene), 
             rx.drug2=Chlorhexidine.r,
             ti=clust))
  cat("\n")
}

enter image description here

Brian Wiley
  • 485
  • 2
  • 11
  • 21
  • Could it be that your `plot.exons` function is set up to do so? Where's the code for that? I'm sure if you try to do a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), you'll either figure it out yourself or get very quick answers. – Fons MA Mar 01 '21 at 23:56
  • It returns a ggplot object. Ok i will set a reprex up. – Brian Wiley Mar 01 '21 at 23:57

0 Answers0