Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save schluppeck/871b4d2abcff3a0b852d025296f5fbb0 to your computer and use it in GitHub Desktop.
Save schluppeck/871b4d2abcff3a0b852d025296f5fbb0 to your computer and use it in GitHub Desktop.
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