Skip to content

Commit

Permalink
FIX: error in count (A & B & !C & D) part. (#3)
Browse files Browse the repository at this point in the history
* Adapt to using 'data.table'.
* Add code to check such typos.
* Update version to 0.1.1
  • Loading branch information
yanlinlin82 committed Dec 17, 2019
1 parent 2671178 commit ef2769e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 35 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ggvenn
Title: Venn Diagram by ggplot2
Version: 0.1.0
Version: 0.1.1
Authors@R: person(given = "Linlin", family = "Yan",
role = c("aut", "cre"),
email = "yanlinlin82@gmail.com",
Expand All @@ -10,4 +10,4 @@ Depends: dplyr, grid, ggplot2
License: MIT
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.1
RoxygenNote: 7.0.2
44 changes: 25 additions & 19 deletions R/ggvenn.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ gen_text_pos_4 <- function() {
"ABC", -0.5, -0.2, 0.5, 0.5, TRUE, TRUE, TRUE, FALSE,
"BCD", 0.5, -0.2, 0.5, 0.5, FALSE, TRUE, TRUE, TRUE,
"ACD", -0.3, -1.1, 0.5, 0.5, TRUE, FALSE, TRUE, TRUE,
"BCD", 0.3, -1.1, 0.5, 0.5, FALSE, TRUE, TRUE, TRUE,
"ABD", 0.3, -1.1, 0.5, 0.5, TRUE, TRUE, FALSE, TRUE,
"ABCD", 0, -0.7, 0.5, 0.5, TRUE, TRUE, TRUE, TRUE)
}
gen_label_pos_4 <- function() {
Expand All @@ -165,39 +165,42 @@ prepare_venn_data <- function(data, columns = NULL) {
columns = data %>% select_if(is.logical) %>% names
}
if (length(columns) == 2) {
stopifnot(is.logical(data[,columns[[1]], drop = TRUE]))
stopifnot(is.logical(data[,columns[[2]], drop = TRUE]))
stopifnot(is.logical(as_tibble(data)[,columns[[1]], drop = TRUE]))
stopifnot(is.logical(as_tibble(data)[,columns[[2]], drop = TRUE]))
d <- gen_circle_2()
d1 <- gen_text_pos_2() %>% mutate(n = 0)
stopifnot((d1 %>% count(A, B) %>% with(n)) == 1)
for (i in 1:nrow(d1)) {
d1$n[[i]] <- sum((!xor(d1$A[[i]], data[,columns[[1]]])) &
(!xor(d1$B[[i]], data[,columns[[2]]])))
d1$n[[i]] <- sum((!xor(d1$A[[i]], as_tibble(data)[,columns[[1]]])) &
(!xor(d1$B[[i]], as_tibble(data)[,columns[[2]]])))
}
d2 <- gen_label_pos_2()
} else if (length(columns) == 3) {
stopifnot(is.logical(data[,columns[[1]], drop = TRUE]))
stopifnot(is.logical(data[,columns[[2]], drop = TRUE]))
stopifnot(is.logical(data[,columns[[3]], drop = TRUE]))
stopifnot(is.logical(as_tibble(data)[,columns[[1]], drop = TRUE]))
stopifnot(is.logical(as_tibble(data)[,columns[[2]], drop = TRUE]))
stopifnot(is.logical(as_tibble(data)[,columns[[3]], drop = TRUE]))
d <- gen_circle_3()
d1 <- gen_text_pos_3() %>% mutate(n = 0)
stopifnot((d1 %>% count(A, B, C) %>% with(n)) == 1)
for (i in 1:nrow(d1)) {
d1$n[[i]] <- sum((!xor(d1$A[[i]], data[,columns[[1]]])) &
(!xor(d1$B[[i]], data[,columns[[2]]])) &
(!xor(d1$C[[i]], data[,columns[[3]]])))
d1$n[[i]] <- sum((!xor(d1$A[[i]], as_tibble(data)[,columns[[1]]])) &
(!xor(d1$B[[i]], as_tibble(data)[,columns[[2]]])) &
(!xor(d1$C[[i]], as_tibble(data)[,columns[[3]]])))
}
d2 <- gen_label_pos_3()
} else if (length(columns) == 4) {
stopifnot(is.logical(data[,columns[[1]], drop = TRUE]))
stopifnot(is.logical(data[,columns[[2]], drop = TRUE]))
stopifnot(is.logical(data[,columns[[3]], drop = TRUE]))
stopifnot(is.logical(data[,columns[[4]], drop = TRUE]))
stopifnot(is.logical(as_tibble(data)[,columns[[1]], drop = TRUE]))
stopifnot(is.logical(as_tibble(data)[,columns[[2]], drop = TRUE]))
stopifnot(is.logical(as_tibble(data)[,columns[[3]], drop = TRUE]))
stopifnot(is.logical(as_tibble(data)[,columns[[4]], drop = TRUE]))
d <- gen_circle_4()
d1 <- gen_text_pos_4() %>% mutate(n = 0)
stopifnot((d1 %>% count(A, B, C, D) %>% with(n)) == 1)
for (i in 1:nrow(d1)) {
d1$n[[i]] <- sum((!xor(d1$A[[i]], data[,columns[[1]]])) &
(!xor(d1$B[[i]], data[,columns[[2]]])) &
(!xor(d1$C[[i]], data[,columns[[3]]])) &
(!xor(d1$D[[i]], data[,columns[[4]]])))
d1$n[[i]] <- sum((d1$A[[i]] == as_tibble(data)[,columns[[1]], drop = TRUE]) &
(d1$B[[i]] == as_tibble(data)[,columns[[2]], drop = TRUE]) &
(d1$C[[i]] == as_tibble(data)[,columns[[3]], drop = TRUE]) &
(d1$D[[i]] == as_tibble(data)[,columns[[4]], drop = TRUE]))
}
d2 <- gen_label_pos_4()
} else {
Expand All @@ -212,6 +215,7 @@ prepare_venn_data <- function(data, columns = NULL) {
if (length(columns) == 2) {
d <- gen_circle_2()
d1 <- gen_text_pos_2() %>% mutate(n = 0)
stopifnot((d1 %>% count(A, B) %>% with(n)) == 1)
for (i in 1:nrow(d1)) {
d1$n[[i]] <- sum((!xor(d1$A[[i]], a2 %in% data[[columns[[1]]]])) &
(!xor(d1$B[[i]], a2 %in% data[[columns[[2]]]])))
Expand All @@ -220,6 +224,7 @@ prepare_venn_data <- function(data, columns = NULL) {
} else if (length(columns) == 3) {
d <- gen_circle_3()
d1 <- gen_text_pos_3() %>% mutate(n = 0)
stopifnot((d1 %>% count(A, B, C) %>% with(n)) == 1)
for (i in 1:nrow(d1)) {
d1$n[[i]] <- sum((!xor(d1$A[[i]], a2 %in% data[[columns[[1]]]])) &
(!xor(d1$B[[i]], a2 %in% data[[columns[[2]]]])) &
Expand All @@ -229,6 +234,7 @@ prepare_venn_data <- function(data, columns = NULL) {
} else if (length(columns) == 4) {
d <- gen_circle_4()
d1 <- gen_text_pos_4() %>% mutate(n = 0)
stopifnot((d1 %>% count(A, B, C, D) %>% with(n)) == 1)
for (i in 1:nrow(d1)) {
d1$n[[i]] <- sum((!xor(d1$A[[i]], a2 %in% data[[columns[[1]]]])) &
(!xor(d1$B[[i]], a2 %in% data[[columns[[2]]]])) &
Expand Down
30 changes: 21 additions & 9 deletions man/geom_venn.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 14 additions & 5 deletions man/ggvenn.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ef2769e

Please sign in to comment.