jokergoo / circlize

Circular visualization in R
http://jokergoo.github.io/circlize_book/book/
Other
968 stars 146 forks source link

GenomicLabels clumped together #315

Closed jinghuazhao closed 2 years ago

jinghuazhao commented 2 years ago

I have data such as these,

chr start end log10p label category chr9 107543283 107543283 10.9065783148378 ABCA1 1 chr17 66863433 66863433 6.18708664335714 ABCA8 4 ...

but circos.genomicLabels put all labels, just in the first two quadrants,

image

The code seems fairly standard,

circos.clear() circos.par(start.degree = 90, track.margin = c(0.005, 0.005), cell.padding = c(0.001, 0.01, 0.01, 0.001)) circos.initializeWithIdeogram(chromosome.index=paste0("chr",1:22),plotType = NULL) circos.genomicLabels(QTL_labels, labels=QTL_labels[["label"]], side = "outside", cex = 0.3, line_lwd = 0.8, padding=0.8, connection_height = convert_height(8, "mm"), line_col = QTL_labels[["category"]], col = QTL_labels[["category"]])

Are there any suggestions? Thank you!

jpmcelderry commented 2 years ago

I'm having the same issue:

Screen Shot 2022-05-06 at 8 46 12 PM

The code looks like this:

circos.par(start.degree=85,gap.degree=10,xaxis.clock.wise=FALSE)
circos.genomicInitialize(chrM,plotType = NULL)
circos.genomicTrack(chrM,ylim=c(-10,10),track.margin=c(.005,0.005), panel.fun = function(region, value, ...) {
  circos.rect(xleft=chrM$start,ybottom = 0,xright = chrM$stop,ytop = CELL_META$cell.ylim[2]*chrM$strand,col=1:nrow(chrM))
  circos.genomicAxis(h="bottom",direction="inside",labels.cex=0.8,major.by = 1000)
},
track.height = 0.1, bg.border = NA)
circos.genomicLabels(chrM,labels.column = 5,side="inside",
                     col=c(1:(nrow(chrM)-1),1),line_col = c(1:(nrow(chrM)-1),1))

where chrM is just a standard BED file formatted like so:

  chrom start stop strand   name complex 
1  chrM     0  576      0 D-Loop   other
2  chrM   577  647      1     TF mt tRNA
3  chrM   648 1601      1   RNR1 mt rRNA
4  chrM  1602 1670      1     TV mt tRNA
5  chrM  1671 3229      1   RNR2 mt rRNA
6  chrM  3230 3304      1    TL1 mt tRNA

I've tried downgrading to 0.4.10 as others suggested which fixed this problem but created others, and I'm currently using the latest version of circlize available on GitHub.

jinghuazhao commented 2 years ago

Thank you so much @jpmcelderry; I have used CRAN version (0.4.14) for other successful plots and for this data and version 0.4.15 at the GitHub the problem goes away.

jokergoo commented 2 years ago

I will update the new version to CRAN in the next few weeks.

jpmcelderry commented 2 years ago

I will update the new version to CRAN in the next few weeks.

@jokergoo I'm still having this issue even with version 0.4.15. I've tried updating everything except R itself currently (I'm on version 4.1.1). One thing that did help was commenting out "xaxis.clock.wise=FALSE", which for some reason restored proper behavior but to only part of the plot.

image

jokergoo commented 2 years ago

@jpmcelderry maybe I haven't completely fixed this bug. Can you also send me the data and code so that I can have a test on it?

jpmcelderry commented 2 years ago

@jokergoo

The code is part of a larger script, but here are the relevant portions:

library(tidyverse)
library(ComplexHeatmap)
library(broom)
library(ggpubr)
library(ggrepel)
library(ggsci)
library(gridExtra)
library(circlize)

chrM <- read_delim(file = "chrM_genes.txt",delim='\t',col_names = TRUE,col_types = "cnnn")%>%
  `colnames<-`(c('name','start','stop','strand'))%>%
  mutate(name=str_sub(name,4,nchar(name)),chrom="chrM")%>%
  select(chrom,start,stop,strand,name)

circos.clear()
circos.par(start.degree=85,gap.degree=10)#,xaxis.clock.wise=FALSE)
circos.genomicInitialize(chrM,plotType = NULL)
circos.genomicTrack(ylim=c(-10,10),track.margin=c(.005,0.005), panel.fun = function(region, value, ...) {
  circos.rect(xleft=chrM$start,ybottom = 0,xright = chrM$stop,ytop = CELL_META$cell.ylim[2]*chrM$strand,col=1:nrow(chrM))
  circos.genomicAxis(h="bottom",direction="inside",labels.cex=0.8,major.by = 1000)
},
track.height = 0.1, bg.border = NA)
circos.genomicLabels(chrM,labels.column = "name",side="inside",
                     col=c(1:(nrow(chrM)-1),1),line_col = c(1:(nrow(chrM)-1),1),connection_height = mm_h(8),padding=0.2)

The annotations file is attached. Appreciate your help!

chrM_genes.txt

jinghuazhao commented 2 years ago

I use R 4.2.0 and 0.4.15 works OK for my problem but not this one.

jokergoo commented 2 years ago

Hi @jinghuazhao , thanks for the data. Yes that was a bug. Now I have fixed it. Please update from GitHub.

image
jinghuazhao commented 2 years ago

Thank you @jpmcelderry and @jokergoo for the information and bug fix -- I will update these from GitHub. Best. Jing Hua

jpmcelderry commented 2 years ago

@jokergoo Update worked, thank you! It seems that setting the "xaxis.clock.wise" option to 'FALSE' still causes the labels to clump, but most importantly default facing is working again. Thank you!

jokergoo commented 2 years ago

Thanks for discovering it! Now it is fixed.

image
jpmcelderry commented 2 years ago

Amazing, thank you so much @jokergoo