teunbrand / ggnomics Goto Github PK
View Code? Open in Web Editor NEWA small project to add ggplot2 extensions
Home Page: https://teunbrand.github.io/ggnomics/
License: Other
A small project to add ggplot2 extensions
Home Page: https://teunbrand.github.io/ggnomics/
License: Other
For discrete data, implement a scale_x_dendrogram
/scale_y_dendrogram
function that take a hclust
-class object compatible with the discrete values of the data, reorders the axis according to the dendrogram and draws the tree as part of the axis.
Potential later addition could be to dynamically generate the hclust data given the data, instead of having to rely on the user to supply it.
Since it's technically not a rug.
Maybe name it geom_rectmargin / geom_tilemargin.
The tricky part of the code is already there, should be relatively trivial to expand to have the user submit a list of scales of their own design.
Hey, I'm using your facet_nested code to generate stacked bar plots in R. (Super useful function so thanks for that by the way)
Unfortunately the variables I'm using to facet by have an uneven number of observations, so in some of them the bars appear huge while in others they appear small.
I'm still a bit new to the more in depth coding side of R, so I may have missed this but is there a way to vary the size of the nested facets and "even" the observation bars so they're all about the same size?
i.e. Make facets with more observations wider so that the bar width for each observation is the same?
Basically this:
function(input){c(-1,1) * max(abs(input))
So that it can be used with scales:
scale_colour_continuous(limits = that_function)
Should be easy and convenient when scale indicates some kind of log fold change.
For species with acrocentric chromosomes such as mouse, setup_ideograms throws many unhelpful warnings and doesn't work as intended.
Adding to to-do list: make sure grid
and gtable
namespaces are called when appropriate.
Currently, it is a bit of a pain to precisely control what the limits of a facet are. Maybe, there might something that can be done to give more control, something that would work like the following:
position_scales_by_facet(
list(
scale_x_continuous(limits = c(0, 100)),
scale_x_continuous(limits = c(50, 150))
)
)
I have a huge figure (48 outer facets, 2 inner facets, each with 2 parts). If I plot using something like:
tibble %>%
+ mutate(Cluster = fct_relevel(Cluster, unique(tibble$Cluster))) %>%
+ mutate(Genotype = fct_relevel(Genotype, "WT", "mutant")) %>%
+ ggplot(aes(fill = Genotype, x= Genotype, y=Proportion)) +
+ geom_boxplot() +
+ geom_point(pch = 21, position = position_jitterdodge()) +
+ facet_nested(~ Cluster + Timepoint, scales="free") +
+ scale_fill_manual(values=c("skyblue1","darksalmon"))
I get it to work, technically speaking, but all 48 outer facets are all in one row and the plot is unreadable.
Is it possible to implement (or combine with) a facet_wrap(ncol=x,nrow=y)
sort of functionality so I can control how many rows or columns of facets there are?
Hi,
I was using the wonderful function you made of facet_nested (just by pasting the code you posted elsewhere) and after the error of env (and know "object '.int' not found") you suggested to use genomics.
I am a newbie, and I do not know how to sort that out.
Any ideas?
Thanks
It should be biovizBase::getBioColor("CYTOBAND")
, not biovizBase::getBioColor("CYTOBANDS")
Basically to have a GRanges object (chromsome:start-end parametrisation) as the position on the x- or y-axis and have a coord_* function reflect this.
The struggle at the moment is to have a vector-like implementation of GRanges as a single column in a base R data.frame. See my related SO question: https://stackoverflow.com/questions/59370461/granges-as-column-in-basedata-frame
facet_grid behaviour:
[ 1 ][ 2 ][ 2 ]
[ 3 ][ 3 ][ 4 ]
What it does now:
[ 1 ][ 2 ]
[ 3 ][ 4 ]
What it should do:
[ 1 ][ 2 ]
[ 3 ][ 3 ][ 4 ]
Should set defaults to do third option, give argument to do second option.
KDEs exist in ggplot, how hard could it be to plot a line of theoretical densities (dnorm, dlnorm, dcauchy, dt, etc.) given parameters estimated from the x-variable?
Figure out why, fix it and write some tests.
Error in data.frame(x = c(1, base::rbind(getMethod("start", "Rle")(object), :
argument is missing, with no default
The highlight position seems to take over position in the ideogram when axis is reversed.
Should write a helper function to import bigwig tracks as a polygon, which would probably be general for converting any RleList to polygons.
The 45 degree angle rotation could be a position function. Could add options such as clip = c("lower", "upper", "neither")
or sawtooth = FALSE
. Should convert raster-like data to polygon style parametrisation.
I'm able to get nested rows, but I'm at a loss on how to specify columns for facet_nested. Do you have any examples of what the function expects?
A function that accepts GRanges contructed from GTF/GFF files as input and formats it such that it would display the gene models appropriately. Combination of rectangles and segments.
ggsubset <- function(rowtest = NULL, omit = NULL) {
rowtest <- substitute(rowtest)
if (is.null(rowtest)) {
rowtest <- substitute(TRUE)
}
omit <- substitute(omit)
if (is.null(omit)) {
omit <- substitute(TRUE)
}
function(x) subset.data.frame(x, eval(rowtest), -eval(omit))
}
To add bigwig tracks, bed annotation, position annotation and whatnot. Should by default reverse the y-axis of the Hi-C layer.
I have the feeling that people sometimes choose to use this package for other things than plotting genomics related data (and there is nothing wrong with that). The following functions are not specifically related to genomics:
facet_nested()
facetted_pos_scales()
force_panelsizes()
ggsubset()
geom_pointpath()
scale_listed()
scale_fill/colour_multi()
stat_theodensity()
Would it make sense to move these to a seperate repository? Any name suggestions for that repository? I'm mainly asking so that people that don't work with genomics data don't accidentally step in a dependency minefield (see also #11 ). Feel free to leave an opinion as comment if you've used the ggnomics package!
Like geom_rug(), but for rectangles. This might be convenient for annotating peaks when plotting genomic tracks.
Would probably be nice if one could give the input of geom_raster()
to a geom function, and specify a rotation angle, shear or 2x2 matrix to transform the output using linear algebra, outputting the pixels as small polygons.
Hi,
I have been using facet_nested() quite a lot recently. Thank you for creating such a useful tool! I was wondering if it was possible to create a fixed x-axis per nested grid. Currently, the plot looks like this:
This is the code that I used (displaying only the relevant grid parameters):
ggplot(KEGG_df) +
facet_nested(~ Enrichment + ControlDesign, nest_line = TRUE,
scale = "free", space = "free_x") +
geom_point(mapping = aes(x = IncubationTime, y = KEGGdescr,
color = -log10(FDR), size = EnrichmentScore)) +
theme(strip.text = element_text(size = 8))
The x-axis of the grid 'Down' shows all labels. In contrast, the labels '4h' and '120h - 24h' are missing from the grid 'Up' since these conditions have no upregulated KEGG pathways. The plot layout that I would like to create is:
I have tried using the parameter scale = "fixed" instead of scale = "free". However, this caused that all x-axis labels are displayed in each grid:
Is there a way to fix the x-axis labels per nested grid? Meaning that the labels for both grids of 'Control: 0h' are identical and that the labels of both grids of 'Control: previous incubation time' are identical. If you require more information, please let me know. Thank you in advance!
Kind regards,
Michelle
Currently the package seems to contain 3 dependencies from Bioconductor
Installing these are a bit of a frustration, so adding these to the front page, might prove helpful?
The very last reply on this devtools issue seems to mention something about adding bioViews: (pkgs)
to the description.
Following your latter example in this question, but failing to use the correct data (eg. using the question provided data), throws a very unhelpful error.
Error in vapply(missing, var_list, character(1)) :
object 'var_list' not found
Adding an error check for var_list in the function combine_nested_vars would be wonderful.
Mainly for the fill values of the matrix.
hic_obsexp
: A kind of observed over expected transformation for fill values. Would be possible to add a kind of decay
parameter that takes a vector of pre-computed normalisation values. For example those derived from all chromosomes or that particular chromosome arm.
hic_diff
: only in case a second experiment has been defined, could take the difference between exp1 and exp2 and output that as a computed variable.
hic_eigen
: performs eigenvalue decomposition on the matrix. Can have as argument which eigenvalues to retain.
hic_cor
calculates the correlation matrix of the Hi-C map
hic_cov
calculates the covariance matrix of the Hi-C map
Ideally there would be some elegant way to perform subsequent stat transformations such that e.g. the eigenvalue decomposition can be performed on the hic_obsexp
values or hic_cov
values.
It should take up to two experiments and a GRanges region as input. Would output a matrix or polygon, depending on the parameters. Ideally, there would be a plot-wide setting for the regions that the geom could inherit and apply. Could maybe add options to allow chromosomes to be columns, for facetting purposes, and add custom facet parameters to be passed on as a named vector.
Hi,
with a recent update to ggplot2, there was a change to the function eval_facets().
tidyverse/ggplot2@5e6b1e5#diff-b8cdc3f131782de7db4bd9302d590821
The arguement env is no longer supported. This causes an error when using facet_nested(). A few changes in facet_nested.R might solve these errors:
Thanks for this wonderful package.
Max
Hello,
I tried the posted example but it didn't work. Can you check what went wrong?
Thanks for this pretty cool package!
library(tidyverse, warn.conflicts = FALSE)
library(ggnomics)
phi <- 2/(1 + sqrt(5))
df <- iris
df$nester <- ifelse(df$Species == "setosa",
"Short Leaves",
"Long Leaves")
g <- ggplot(df, aes(x = Sepal.Length, y = Petal.Length)) +
geom_point(aes(sepal.width = Sepal.Width),
ggsubset(Species == "setosa")) +
geom_point(aes(petal.length = Petal.Length),
ggsubset(Species == "versicolor")) +
geom_point(aes(petal.width = Petal.Width),
ggsubset(Species == "virginica")) +
facet_nested(~ nester + Species, scales = "free")
#> Warning: Ignoring unknown aesthetics: sepal.width
#> Warning: Ignoring unknown aesthetics: petal.length
#> Warning: Ignoring unknown aesthetics: petal.width
g
#> Error in FUN(X[[i]], ...): unused argument (env = env)
Created on 2020-03-24 by the reprex package (v0.3.0)
The lines indicating the nesting will return error:
Error in gtable_add_grob(panel_table, indicator, t = switch(orient, x = pos_y + :
Not all inputs have either length 1 or same length same as 'grobs'
Probably fixable by providing a list of indicator grobs the same length as insert_here
.
Hi! I have created a barplot and arranged the x-axis accordingly to how I want it. However, once I run it through facet_nested, it changes the order.
I've tried to get ideas and help from stackoverflow, but have received no reply so it might be an issue that hasn't been encountered before. https://stackoverflow.com/questions/58235789/how-do-i-order-x-axis-within-facet-nested?noredirect=1#comment102845843_58235789
Would there be a function within facet_nested that could work around this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.