Search code examples
rplotvisualizationbioinformaticsbioconductor

How to re-adjust figure size of trackViewer Vignette lollipopPlot and avoid x-axis cut off


I am new to trackViewer Vignette lollipopPlot, I am experimenting with the plot. However, my plot looked very wide and have white space for some reason that I would like to readjust the width and height of the figure. I tried changing value of cex but that did not help. Also I have problem with x-axis labels being cut off. I believe this can be solve by re-adjusting the figure size, how do I do that?

I am using RStudio Version 1.2.5033 and trackViewer Version 1.24.2.

Here is my code:

library(trackViewer)
myfile = read.csv("myfile.bed", header = FALSE, sep = "\t")
> myfile
                 V1       V2      V3 V4
1 label1 27146879 #E1C877  5
2 label2 27146883 #E7B105  1
3 label3 27146913 #2F1CDB  1
4 label4 27146957 #B169CD  1
5 label5 27147054 #6EB934  1
6 label6 27147099 #D4D592  1
> sample.gr <- GRanges("chr6", IRanges(myfile$V2, names=myfile$V1), color=myfile$V3, score=myfile$V4)
> features <- GRanges("chr6", IRanges(myfile$V2))
> sample.gr.rot <- sample.gr
> sample.gr.rot$label.parameter.rot <- 70
> lolliplot(sample.gr.rot, features, cex = 1.1, yaxis.gp = gpar(fontsize=18, lwd=2), ylab = FALSE, xaxis.gp = gpar(fontsize=11))

Thank you so much in advance

Here is the plot: enter image description here


Solution

  • Here is a modified example from the vignette:

    library(trackViewer)
    # in case your plot margins are too large, you can set them e.g.:
    par(mar=c(0.5, 0,0,.5))
    SNP <- c(10, 12, 1400, 1402)
    sample.gr <- GRanges("chr1", IRanges(SNP, width=1, names=paste0("snp", SNP)))
    sample.gr$color <- c("darkblue", "blue", "red", "darkred")
    sample.gr$score <- c(1,2,1,5)
    features <- GRanges("chr1", IRanges(c(1, 501, 1001), 
                                        width=c(120, 400, 405),
                                        names=paste0("block", 1:3)))
    lolliplot(sample.gr, features, yaxis=FALSE)
    

    
    # export as png with pre-set dimensions
    png("testplottt1.png", width=600, height = 200)
    lolliplot(sample.gr, features, yaxis=FALSE)
    dev.off()
    

    this is the exported file: plot