I am looking for a package similar to ggpubr to calculate and plot the statistic differences between some density plots. it would be great if it could work as a ggplot2 extension.
I've tried ggpubr but I think I should rearrange the data.frame quite a lot to make it work.
Does anyone have any suggestions?
This is an example for one of the plots I'd like to add some stats on top:
library(tidyverse)
library(plotly)
library(pheatmap)
library(RColorBrewer)
library(cowplot)
library(scales)
library(UpSetR)
library(magrittr)
library(multipanelfigure)
library(purrr)
library(igraph)
library(ggraph)
library(grid)
library(gtable)
library(gridExtra)
library(ComplexHeatmap)
library(ggridges)
library(ggplotify)
library(ggpubr)
library(ggpval)
mycols_values <- c("TG_baits" = "darkgrey", # Colors are coming from RColorbrewer brewer.pal(11, "RdYlBu")
"TAL1" = '#d73027',
"Promoter_flanking_region" = '#f46d43',
"Promoter" = "#fdae61",
"Intron" = "#fee090",
"intergenic_region" = "#a1d99b",
"GATA2" = "#ffffbf",
"GATA1" = "#e0f3f8",
"FLI1" = "#abd9e9",
"Exons" = "#74add1",
"Enhancer" = "#4575b4",
"CTCF" = "#313695"
)
df_var <- structure(list(Promoter.id1 = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), Distance_bait_prey = c(120536,
118081, 109646, 105159, 97202, 71739, 43239, 42450, 41350, 35391,
30686, 22941, 2584, 1873, 4264, 10040, 10794, 18074, 32473, 44556,
292007, 390016, 0, 0, 142512, 131396, 110989, 109562, 104713,
95261, 86678, 69790, 55695, 35697, 2889, 3958, 38661, 43660,
44783, 49321, 54148, 99101, 99977, 119272, 1484139, 409111, 386732,
123910, 118993, 115927, 113762, 79247, 66060, 49530, 40555, 37697,
30777, 9457, 22946, 36503, 67066, 77248, 205036, 317144, 0, 0,
685454, 118907, 111509, 82273, 40797, 31511, 2699, 3438, 9215,
17249, 0, 0, 213732, 94776, 0, 86753, 69263, 67025, 66564, 54178,
51116, 50332, 43140, 41183, 40896, 34972, 24871, 23565, 10131,
7517, 24279, 29130, 30790, 33482), node.class2 = c("Intron",
"Intron", "Intron", "Intron", "Intron", "intergenic_region",
"Promoter_flanking_region", "Promoter_flanking_region", "Exons",
"Exons", "Exons", "intergenic_region", "Promoter_flanking_region",
"Promoter_flanking_region", "Exons", "Promoter", "Promoter",
"Promoter", "intergenic_region", "Intron", "intergenic_region",
"Intron", "Intron", "Intron", "Exons", "Intron", "CTCF", "Intron",
"Intron", "Intron", "Gene_name", "intergenic_region", "intergenic_region",
"Exons", "Promoter_flanking_region", "Exons", "Promoter_flanking_region",
"Promoter_flanking_region", "Intron", "Intron", "Exons", "Exons",
"Intron", "intergenic_region", "Intron", "Enhancer", "Promoter",
"Intron", "Intron", "Intron", "Intron", "Promoter", "Promoter_flanking_region",
"Promoter_flanking_region", "Exons", "Exons", "Intron", "Promoter",
"intergenic_region", "Exons", "Intron", "Exons", "CTCF", "Exons",
"intergenic_region", "Exons", "Intron", "Intron", "CTCF", "Gene_name",
"Exons", "Exons", "Promoter_flanking_region", "Exons", "Promoter",
"Promoter", "Exons", "intergenic_region", "CTCF", "Promoter",
"Intron", "CTCF", "Promoter", "Promoter", "Promoter", "CTCF",
"CTCF", "CTCF", "Promoter_flanking_region", "Promoter", "Promoter",
"Promoter", "CTCF", "CTCF", "Promoter_flanking_region", "Promoter",
"CTCF", "Promoter", "Promoter", "Promoter")), row.names = c(NA,
100L), class = "data.frame")
df_var$Distance_bait_prey <- str_replace_all(df_var$Distance_bait_prey, "^0","1000000000000")
ggplot(df_var, aes(x = log10(as.double(Distance_bait_prey)),
y = node.class2,
fill = node.class2),
alpha = 0.7) +
geom_density_ridges(aes(point_color = node.class2),
scale = 2,
alpha = 0.6,
panel_scaling = TRUE,
#calc_ecdf = TRUE,
#quantiles = c(0.025, 0.975),
jittered_points = TRUE,
position = position_points_sina(rel_min = 0.02, rel_max = 0.75, seed = NULL),
quantile_lines = TRUE,
point_size = 0.5,
point_alpha = 1) +
scale_point_color_hue(l = 40, guide=FALSE) +
scale_discrete_manual(aesthetics = "point_color", values = mycols_values, guide=FALSE) +
scale_x_continuous(limits = c(2,7),
name = "Distance Bait-prey [log10(bp)]",
breaks = seq(2, 7, by = 1)) +
labs(title = str_sub(name1, 1,-5),
fill = "Distances grouped by Feature") +
scale_fill_manual(values = mycols_values) +
guides(fill = guide_legend(reverse = TRUE)) +
theme_classic() +
theme(plot.title = element_text(size = 54),
axis.text.x = element_text(angle = 0, size = 16),
axis.text.y = element_blank(),
axis.title.y = element_blank(),
axis.title.x = element_text(size = 0),
axis.ticks.y = element_blank(),
legend.title = element_text(size = 30),
legend.text = element_text(size = 22),
legend.position = "bottom" ,
legend.key.size = unit(1, "cm"),
panel.grid.major = element_line(colour = "grey90",
linetype = "solid",
size = 0.3))
sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS 10.14.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggpval_0.2.2 ggpubr_0.2.2.999 usethis_1.5.0 devtools_2.0.2
[5] ggplotify_0.0.3 ggridges_0.5.1 ComplexHeatmap_1.20.0 gridExtra_2.3
[9] gtable_0.3.0 ggraph_1.0.2 igraph_1.2.4.1 multipanelfigure_2.0.2
[13] magrittr_1.5 UpSetR_1.4.0 scales_1.0.0 cowplot_1.0.0
[17] RColorBrewer_1.1-2 pheatmap_1.0.12 plotly_4.9.0 forcats_0.4.0
[21] stringr_1.4.0 dplyr_0.8.3 purrr_0.3.2 readr_1.3.1
[25] tidyr_0.8.3 tibble_2.1.3 ggplot2_3.2.1 tidyverse_1.2.1
loaded via a namespace (and not attached):
[1] nlme_3.1-139 fs_1.3.1 lubridate_1.7.4
[4] httr_1.4.0 rprojroot_1.3-2 tools_3.5.1
[7] backports_1.1.4 utf8_1.1.4 R6_2.4.0
[10] lazyeval_0.2.2 colorspace_1.4-1 GetoptLong_0.1.7
[13] withr_2.1.2 tidyselect_0.2.5 prettyunits_1.0.2
[16] processx_3.3.1 curl_3.3 compiler_3.5.1
[19] cli_1.1.0 rvest_0.3.3 assertive.properties_0.0-4
[22] xml2_1.2.0 desc_1.2.0 labeling_0.3
[25] assertive.files_0.0-2 callr_3.2.0 digest_0.6.20
[28] assertive.numbers_0.0-2 pkgconfig_2.0.2 htmltools_0.3.6
[31] sessioninfo_1.1.1 htmlwidgets_1.3 rlang_0.4.0
[34] GlobalOptions_0.1.0 readxl_1.3.1 rstudioapi_0.10
[37] shape_1.4.4 gridGraphics_0.4-1 farver_1.1.0
[40] generics_0.0.2 jsonlite_1.6 fansi_0.4.0
[43] Rcpp_1.0.2 munsell_0.5.0 viridis_0.5.1
[46] stringi_1.4.3 assertive.base_0.0-7 yaml_2.2.0
[49] MASS_7.3-51.4 pkgbuild_1.0.3 plyr_1.8.4
[52] ggrepel_0.8.1 crayon_1.3.4 lattice_0.20-38
[55] haven_2.1.0 circlize_0.4.6 hms_0.4.2
[58] magick_2.0 ps_1.3.0 pillar_1.4.2
[61] rjson_0.2.20 ggsignif_0.6.0 reshape2_1.4.3
[64] codetools_0.2-16 pkgload_1.0.2 glue_1.3.1
[67] remotes_2.0.4 data.table_1.12.2 modelr_0.1.4
[70] tweenr_1.0.1 cellranger_1.1.0 polyclip_1.10-0
[73] assertthat_0.2.1 ggforce_0.2.2 broom_0.5.2
[76] assertive.types_0.0-3 viridisLite_0.3.0 rvcheck_0.1.3
[79] memoise_1.1.0