Skip to content

Instantly share code, notes, and snippets.

@trinker
Last active April 3, 2020 13:24
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save trinker/31edc08d0a4ec4c73935a23040c2f6cb to your computer and use it in GitHub Desktop.
Save trinker/31edc08d0a4ec4c73935a23040c2f6cb 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()
@trinker
Copy link
Author

trinker commented Sep 30, 2016

##    animal         x         y diameters labels
## 1:    dog 0.5125237 0.5302827 0.4768272      A
## 2:    dog 0.6491196 0.5636101 0.3794698      B
## 3:    dog 0.4660207 0.4599955 0.4523580      D
## 4:    dog 0.3723360 0.4461117 0.4352817      C
## 5:    cat 0.4965841 0.4785102 0.3888408      A
## 6:    cat 0.4214388 0.3999541 0.3568248      B
## 7:    cat 0.4488481 0.5360400 0.4460310      C
## 8:    cat 0.6331290 0.5854957 0.4087942      D

capture

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment