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

how to rescale and align genes of different size? #75

Open
xyz0o opened this issue Mar 23, 2024 · 1 comment
Open

how to rescale and align genes of different size? #75

xyz0o opened this issue Mar 23, 2024 · 1 comment

Comments

@xyz0o
Copy link

xyz0o commented Mar 23, 2024

I am trying to show TEs around inversion breakpoints. Two of my inversions are extremely short so the TE depiction for other inversions is not visible. how can I get around this issue?
This is my code

ggplot(dfg, aes(xmin = start, xmax = end, y = Gene, fill = element, 
                forward = orientation)) +
  geom_gene_arrow() +
  facet_wrap(~ Gene, scales = "free", ncol = 1) +
  scale_fill_brewer(palette = "Set3") +
  geom_blank(data = dfg, aes(forward = 1)) +
  theme_genes()

for example, for gene4, I have many TEs, but due to scale they are not visible

gene4 Breakpoint 3994117 3994117 1
gene4 Breakpoint 11174374 11174375 1
gene4 TE1 11174718 11174764 0
gene4 TE2 11176065 11176105 1
gene4 TE3 11176070 11176111 0
gene4 TE4 11176124 11176330 1
gene4 TE5 11176616 11176706 1

image

Thanks

@wilkox
Copy link
Owner

wilkox commented Mar 23, 2024

I don't think there's a clean way to do this, but a good starting point might be to break down each region into smaller subplots then compose them with the patchwork package:

library(tidyverse)
library(gggenes)
library(patchwork)

dfg <- tribble(
  ~Gene   , ~element     , ~start   , ~end     , ~orientation ,
  "gene4" , "Breakpoint" , 3994117  , 3994117  , 1            ,
  "gene4" , "Breakpoint" , 11174374 , 11174375 , 1            ,
  "gene4" , "TE1"        , 11174718 , 11174764 , 0            ,
  "gene4" , "TE2"        , 11176065 , 11176105 , 1            ,
  "gene4" , "TE3"        , 11176070 , 11176111 , 0            ,
  "gene4" , "TE4"        , 11176124 , 11176330 , 1            ,
  "gene4" , "TE5"        , 11176616 , 11176706 , 1
)

gene4_left <- ggplot(
  filter(dfg, start < 10000000),
  aes(xmin = start, xmax = end, y = Gene, fill = element, forward = orientation)
) +
  geom_gene_arrow() +
  scale_fill_brewer(palette = "Set3") +
  theme_genes()

gene4_right <- ggplot(
  filter(dfg, start >= 10000000),
  aes(xmin = start, xmax = end, y = Gene, fill = element, forward = orientation)
) +
  geom_gene_arrow() +
  scale_fill_brewer(palette = "Set3") +
  theme_genes()

gene4_left + gene4_right + plot_layout(guides = "collect")

Created on 2024-03-24 with reprex v2.1.0

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