Giter Club home page Giter Club logo

ggvd's Introduction

ggvd

Another implementation of Venn diagrams in ggplot2. Simple functions to generate 2-4 way Venn diagrams using ‘ggplot2’ with minimal dependencies.

Takes the good parts of ggvenn and ggVennDiagram.

library(ggplot2)
library(ggvd)
# make some fake data
generate_gene_names <- function(n) {
  gene_letters <- do.call(
    paste0, 
    replicate(3, sample(LETTERS, n, replace = TRUE), simplify = FALSE)
  )
  paste0(gene_letters, sample.int(9, n, replace = TRUE))
}

genes <- generate_gene_names(n = 2000)
# input for venn should be a list
set.seed(42)
results <- list(
  "Sample 1" = sample(genes, 1651),
  "Sample 2" = sample(genes, 687),
  "Sample 3" = sample(genes, 872),
  "Sample 4" = sample(genes, 712)
)
# prepare_venn takes a list and outputs a data.frame in the correct format
venn2 <- prepare_venn(results[1:2], fill = c("blue", "yellow"))
venn3 <- prepare_venn(results[1:3], fill = c("blue", "yellow", "green"))
venn4 <- prepare_venn(results, fill = c("blue", "yellow", "green", "red"))
## 2 way Venn

# discrete
ggplot() +
  geom_venn(aes(set_name = set_name, elements = elements, fill = fill),
            data = venn2, type = "discrete", set_total = TRUE) +
  scale_fill_identity() + 
  theme_void()

# continuous
ggplot() +
  geom_venn(aes(set_name = set_name, elements = elements, fill = count),
            data = venn2, type = "continuous", set_total = TRUE) +
  scale_fill_gradient(low = "white", high = "red") + 
  theme_void()

## 3 way Venn

# discrete
ggplot() +
  geom_venn(aes(set_name = set_name, elements = elements, fill = fill),
            data = venn3, type = "discrete", set_total = TRUE) +
  scale_fill_identity() + 
  theme_void()

# continuous
ggplot() +
  geom_venn(aes(set_name = set_name, elements = elements, fill = count),
            data = venn3, type = "continuous", set_total = TRUE) +
  scale_fill_gradient(low = "white", high = "red") + 
  theme_void()

## 4 way Venn

# discrete
ggplot() +
  geom_venn(aes(set_name = set_name, elements = elements, fill = fill),
            data = venn4, type = "discrete", set_total = TRUE) +
  scale_fill_identity() + 
  theme_void()

# continuous
ggplot() +
  geom_venn(aes(set_name = set_name, elements = elements, fill = count),
            data = venn4, type = "continuous", set_total = TRUE) +
  scale_fill_gradient(low = "white", high = "red") + 
  theme_void()

ggvd's People

Contributors

csdaw avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.