vertesy / ggExpress

ggExpress is the fastest way to create, annotate and and save plots in R.
https://vertesy.github.io/ggExpress
GNU General Public License v3.0
4 stars 2 forks source link

Draw Venn or Euler diagramms with ggExpress #24

Closed vertesy closed 2 years ago

vertesy commented 2 years ago

Draw Venn or Euler diagramms with ggExpress Alternative of MarkdownReports::wvenn()

From Trinker's Gist

if (!require("pacman")) install.packages("pacman")
pacman::p_load(dplyr, venneuler)
pacman::p_load_current_gh('trinker/textshape', 'thomasp85/ggforce')

x <- matrix(sample(0:4, 80, TRUE, c(.6, .1, .1, .1, .1)), ncol=4)

colnames(x) <- LETTERS[1:4]

euler_dat <- split(as.data.frame(x), c(T, F)) %>%
    setNames( c('dog', 'cat')) %>%
    lapply(function(x){ rownames(x) <- letters[1:10]; x}) %>%
    lapply(function(x){
        y <- venneuler(x)
        data.frame(y$centers, diameters = y$diameters, labels = y$labels, stringsAsFactors = FALSE)
    }) %>%
    textshape::bind_list('animal')

euler_dat %>%
    mutate(r = diameters/2) %>%
    ggplot() +
        geom_circle(aes(x0 = x, y0 = y, r = r, fill=labels), alpha = .5) +
        facet_wrap(~animal) +
        geom_text(aes(x = x, y = y, label = labels)) +
        coord_fixed()

Output

Output

vertesy commented 2 years ago

https://www.datanovia.com/en/blog/beautiful-ggplot-venn-diagram-with-r/

vertesy commented 2 years ago

Venn diagramm now implemented!