'R: Empty PNG plot

I want to save a plot as PNG. I wrote a for loop to create a graphic image and heatmap before saving it to PNG. My PNG file is blank.

library(SGSeq)
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
library(BSgenome.Hsapiens.UCSC.hg19)
library(org.Hs.eg.db)

# Plot splice variant(s) unique to N60
var.n60.samFile <- subset(samFile, sample_name %in% "N60")  
# For each of the 15 genes, subset the Granges objects by only the gene
for (i in gene.list$entrez) {
  # Skip gene AQP8 (Entrez ID: 343)
  if (i=="343") {
    next
  }
  else{
    grange.subset <- txf_grange[txf_grange$geneName %in% i]
    # Collapse the ranges of the genes into a single vector
    grange.subset <- unlist(IRanges::reduce(split(grange.subset, grange.subset$geneName)))
    # Run analyzeFeatures
    sgfc_pred <- analyzeFeatures(var.n60.samFile, which=grange.subset)
    # Annotate predicted features
    sgfc_pred <- SGSeq::annotate(sgfc_pred, txf_ucsc)
    # Run analyzeVariants
    sgvc_pred <- analyzeVariants(sgfc_pred)
    # Plot variants
    png("q7plotB.png")
    plotVariants(sgvc_pred, eventID=1, color_novel="red")
    dev.off()
  }
}

Expected output (not exactly the same)

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source