Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlapping text lables #130

Closed
minalj365 opened this issue Oct 17, 2022 · 2 comments
Closed

Overlapping text lables #130

minalj365 opened this issue Oct 17, 2022 · 2 comments

Comments

@minalj365
Copy link

Hi there! Is there any way like geom_text_repel for overlapping labels?
Here is the plot where I have overlapping labels:

image

And this is the code:

gggenome +
  geom_seq(size=1) +         # draw contig/chromosome lines
  geom_bin_label(size = 4) +   # label each sequence 
  geom_gene(aes(fill=gene), size=3) +        # draw genes as arrow
  geom_gene_tag(aes(label=gene), nudge_y=0.2, check_overlap = FALSE, hjust = 0.1) +
  theme(axis.text.x = element_text(size=12), legend.position = "none")
@thackl
Copy link
Owner

thackl commented Oct 19, 2022

I haven't directly implemented that in gggenomes, but you can use ggrepel to do it:

library(gggenomes)

s0 <- tibble(
  seq_id = "A",
  length = 5000
)

g0 <- tibble(
  seq_id = "A",
  start=c(1000, 1500, 1550),
  end=start+50,
  gene=c("fooo", "baaar", "baaaz")
)

gggenomes(g0, s0) +
  geom_seq() + geom_gene() +
  geom_gene_tag(aes(label=gene))

image

library(ggrepel)
gggenomes(g0, s0) +
  geom_seq() + geom_gene() +
  geom_text(aes(x=(x+xend)/2, y=y+.1, label=gene, color="overlapping"), data=genes(),
                  hjust=0, vjust=0, angle=45) +
  geom_text_repel(aes(x=(x+xend)/2, y=y+.2, label=gene, color="repelled"), data=genes(),
                  hjust=0, vjust=0, angle=45, direction = "x")

image

Check out https://ggrepel.slowkow.com/articles/examples.html#align-labels-on-the-top-or-bottom-edge-1 for additional ideas to draw lines between genes and tags, etc...

@minalj365
Copy link
Author

Thank you so much! Really helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants