myles-lewis / locuszoomr

A pure R implementation of locuszoom for plotting genetic data at genomic loci accompanied by gene annotations.
GNU General Public License v3.0
19 stars 5 forks source link

missplaced arrows in genetracks when calling `ggsave` #29

Open nickhir opened 11 hours ago

nickhir commented 11 hours ago

Hi Myles,

I have noticed that when trying to save a locuszoom plot created with the "ggplot option", that some off the arrows which indicate on which strand the gene lies are missplaced.

Take for example this code:

library(locuszoomr)
data(SLE_gwas_sub)  ## limited subset of data from SLE GWAS
library(EnsDb.Hsapiens.v75)

loc <- locus(gene = 'UBE2L3', SLE_gwas_sub, flank = 1e5, ens_db = "EnsDb.Hsapiens.v75") 

scatter <-gg_scatter(loc)
genes <- gg_genetracks(loc)

plot <- patchwork::wrap_plots(scatter, genes, ncol = 1)

plot # <- this will display everything correctly

# this will misplace some arrows
ggsave(plot,
       filename="test.png")

When examining the plot in the "Plots" window everything looks perfect: image

However, when I actually want to save it using ggplot, some arrows are misplaced: test

Any idea why this might happen? I am using locuszoomr_0.3.5, ggplot2_3.5.1, patchwork_1.3.0.9000 and R 4.3.1

Thank you very much in advance!

myles-lewis commented 9 hours ago

Thanks. Strange. Never seen this before. Looks like only the left sided arrow. The ones on the right seem to be ok. Might be a font issue. Possible patch might be to make the arrows all come after the gene name. I will investigate....

nickhir commented 7 hours ago

Interestingly, this produces the "correct" png without any misplaced arrows...

png("test.png")
plot
dev.off()