Forked from trinker/ggplot2 euler (almost venn) diagrams
Created
February 10, 2019 21:55
-
-
Save schluppeck/871b4d2abcff3a0b852d025296f5fbb0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment