Comments (5)
Thank you so much for this @wilkox. This is what I needed.
from gggenes.
Hi ramadatta, you can set the order of the genomes (or indeed any categorical variable mapped to an axis) by making that variable a factor.
If this doesn't work or you need some more help, could you post the code you already have as a reprex?
from gggenes.
Thanks much @wilkox . Will come back to you soon on this.
from gggenes.
library(ggplot2)
library(gggenes)
dummies <- make_alignment_dummies(
example_genes,
aes(xmin = start, xmax = end, y = molecule, id = gene),
on = "genE"
)
ggplot(example_genes, aes(xmin = start, xmax = end, y = factor(molecule), fill = gene)) +
geom_gene_arrow() +
geom_blank(data = dummies) +
facet_wrap(~ molecule, scales = "free", ncol = 1) +
scale_fill_brewer(palette = "Set3") +
theme_genes()
# Creating a presence/absence matrix for example genes
PA_matrix <- as.data.frame(with(example_genes, table(molecule, gene)) > 0L) +0L
PA_matrix
#> genA genB genC genD genE genF protA protB protC protD protE protF
#> Genome1 1 1 1 1 1 1 0 0 1 1 1 1
#> Genome2 1 1 1 1 1 1 1 1 0 0 0 0
#> Genome3 1 1 1 1 1 1 1 1 0 0 0 0
#> Genome4 1 1 1 1 1 1 0 0 0 0 0 0
#> Genome5 1 1 1 1 1 1 0 0 1 1 1 1
#> Genome6 1 1 1 1 1 1 1 1 0 0 0 0
#> Genome7 0 1 1 1 1 1 1 1 1 1 1 1
#> Genome8 0 1 1 1 1 1 1 1 1 1 1 1
# Sorting the presence/absence matrix for example genes
sorted_PA_matrix <- PA_matrix[do.call(order,as.data.frame(PA_matrix)),]
sorted_PA_matrix
#> genA genB genC genD genE genF protA protB protC protD protE protF
#> Genome7 0 1 1 1 1 1 1 1 1 1 1 1
#> Genome8 0 1 1 1 1 1 1 1 1 1 1 1
#> Genome4 1 1 1 1 1 1 0 0 0 0 0 0
#> Genome1 1 1 1 1 1 1 0 0 1 1 1 1
#> Genome5 1 1 1 1 1 1 0 0 1 1 1 1
#> Genome2 1 1 1 1 1 1 1 1 0 0 0 0
#> Genome3 1 1 1 1 1 1 1 1 0 0 0 0
#> Genome6 1 1 1 1 1 1 1 1 0 0 0 0
sorted_genomes <- row.names(sorted_PA_matrix)
sorted_genomes
#> [1] "Genome7" "Genome8" "Genome4" "Genome1" "Genome5" "Genome2" "Genome3"
#> [8] "Genome6"
# Creating sorted_dummies and sorted_example_genes which the final output figure should reflect
sorted_dummies <- dummies[order(unlist(sapply(dummies$molecule, function(x) which(sorted_genomes == x)))),]
sorted_example_genes <- example_genes[order(unlist(sapply(example_genes$molecule, function(x) which(sorted_genomes == x)))),]
#head(example_genes)
#head(sorted_example_genes)
ggplot(sorted_example_genes, aes(xmin = start, xmax = end, y = factor(molecule), fill = gene)) +
geom_gene_arrow() +
geom_blank(data = sorted_dummies) +
facet_wrap(~ molecule, scales = "free", ncol = 1) +
scale_fill_brewer(palette = "Set3") +
theme_genes()
Hi @wilkox ,
Thank you very much for passing the reprex link. It was useful.
Accordingly, I need the final output figure above in the order of the genomes found in the "sorted_PA_matrix"
. Passing sorted_examples_genes
and sorted_dummies
and using factor(molecule)
, could not help me generate the correct order of genomes intended. Can request to know if I am missing something here? Many thanks in advance.
from gggenes.
library(ggplot2)
library(gggenes)
dummies <- make_alignment_dummies(
example_genes,
aes(xmin = start, xmax = end, y = molecule, id = gene),
on = "genE"
)
# Creating a presence/absence matrix for example genes
PA_matrix <- as.data.frame(with(example_genes, table(molecule, gene)) > 0L) +0L
# Sorting the presence/absence matrix for example genes
sorted_PA_matrix <- PA_matrix[do.call(order,as.data.frame(PA_matrix)),]
sorted_genomes <- row.names(sorted_PA_matrix)
# Creating sorted_dummies and sorted_example_genes which the final output figure should reflect
sorted_dummies <- dummies[order(unlist(sapply(dummies$molecule, function(x) which(sorted_genomes == x)))),]
sorted_example_genes <- example_genes[order(unlist(sapply(example_genes$molecule, function(x) which(sorted_genomes == x)))),]
# Convert molecule variable to a factor
sorted_example_genes$molecule <- factor(sorted_example_genes$molecule, levels = unique(sorted_example_genes$molecule))
sorted_dummies$molecule <- factor(sorted_dummies$molecule, levels = unique(sorted_dummies$molecule))
ggplot(sorted_example_genes, aes(xmin = start, xmax = end, y = factor(molecule), fill = gene)) +
geom_gene_arrow() +
geom_blank(data = sorted_dummies) +
facet_wrap(~ molecule, scales = "free", ncol = 1) +
scale_fill_brewer(palette = "Set3") +
theme_genes()
Created on 2020-07-08 by the reprex package (v0.3.0.9001)
from gggenes.
Related Issues (20)
- theme_genes() produces error HOT 3
- Can you modify the length of the following genomic region HOT 3
- Terminator point feature HOT 5
- Deprecate `size` in favour of `linewidth`
- Implement SBOL sequence feature glyphs HOT 3
- Break strand in intra-CDS regions HOT 2
- geom_feature_label text size very small when ncol=1 in facet_wrap HOT 1
- How to prepare for gggenes HOT 3
- Gene Orientation not correct HOT 1
- An incomprehensible error HOT 4
- would be nice for protein people HOT 2
- How about an option to draw an interrupted X-axis? HOT 1
- Genome alignment HOT 1
- error: No "geom_terminator" functions HOT 2
- Can I draw two different arrows simultaneously on a gene HOT 8
- how to rescale and align genes of different size? HOT 1
- Gene length issue HOT 1
- How to deal with larger length for the genes HOT 1
- Calculate the direction of data obtained from gff file HOT 4
- How to use scale_colour_manual to specify color for individual genes HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gggenes.