Skip to content

Commit

Permalink
Adapt to CRAN policies.
Browse files Browse the repository at this point in the history
  • Loading branch information
yanlinlin82 committed Mar 31, 2023
1 parent 1370647 commit 25fd3b5
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.Rhistory
.RData
.Ruserdata
ggvenn.Rcheck/
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ importFrom(dplyr,"%>%")
importFrom(dplyr,as_label)
importFrom(dplyr,as_tibble)
importFrom(dplyr,count)
importFrom(dplyr,filter)
importFrom(dplyr,inner_join)
importFrom(dplyr,mutate)
importFrom(dplyr,select_if)
importFrom(dplyr,tibble)
importFrom(dplyr,tribble)
importFrom(ggplot2,aes)
importFrom(ggplot2,coord_fixed)
importFrom(ggplot2,geom_polygon)
importFrom(ggplot2,geom_segment)
importFrom(ggplot2,geom_text)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,guides)
Expand All @@ -27,3 +30,4 @@ importFrom(grid,gpar)
importFrom(grid,grobTree)
importFrom(grid,polygonGrob)
importFrom(grid,textGrob)
importFrom(stats,na.omit)
4 changes: 4 additions & 0 deletions R/geom_venn.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#' @param show_percentage Show percentage for each set.
#' @param digits The desired number of digits after the decimal point
#' @param label_sep separator character for displaying elements.
#' @param count_column Specify column for element repeat count.
#' @param show_outside Show outside elements (not belongs to any set).
#' @param auto_scale Allow automatically resizing circles according to element counts.
#' @param fill_color Filling colors in circles.
#' @param fill_alpha Transparency for filling circles.
#' @param stroke_color Stroke color for drawing circles.
Expand Down Expand Up @@ -90,6 +93,7 @@ geom_venn <- function(mapping = NULL, data = NULL,
set_name_size = 6,
text_color = "black",
text_size = 4) {
show_outside <- match.arg(show_outside)
l <- layer(mapping = mapping, data = data,
geom = GeomVenn, stat = stat, position = position,
params = list(na.rm = TRUE, ...))
Expand Down
14 changes: 9 additions & 5 deletions R/ggvenn.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#' @param label_sep Separator character for displaying elements.
#' @param count_column Specify column for element repeat count.
#' @param show_outside Show outside elements (not belongs to any set).
#' @param auto_scale Allow automatically resizing circles according to element counts.
#' @return The ggplot object to print or save to file.
#' @examples
#' library(ggvenn)
Expand Down Expand Up @@ -55,8 +56,9 @@
#' ggvenn(a, show_elements = TRUE)
#' ggvenn(d, show_elements = "value")
#' @seealso geom_venn
#' @importFrom dplyr tibble tribble as_tibble %>% select_if mutate count
#' @importFrom ggplot2 ggplot aes geom_polygon geom_text scale_x_continuous scale_y_continuous scale_fill_manual guides coord_fixed theme_void layer
#' @importFrom dplyr tibble tribble as_tibble %>% select_if mutate count filter inner_join
#' @importFrom ggplot2 ggplot aes geom_polygon geom_segment geom_text scale_x_continuous scale_y_continuous scale_fill_manual guides coord_fixed theme_void layer
#' @importFrom stats na.omit
#' @export
ggvenn <- function(data, columns = NULL,
show_elements = FALSE,
Expand Down Expand Up @@ -293,7 +295,7 @@ gen_seg_pos_2 <- function(scale_info) {
df <- tibble(x = x_pos, y = 0, xend = x2_pos, yend = -1.2 * scale_info['a_radius'])
} else if (scale_info['b_radius'] < min_overlap_for_text) {
x2_pos <- x_dist - 1.2 * (scale_info['a_radius'] - scale_info['overlap_size']) / 2
df <- tibble(x = x_pos, y = 0, xend = x2_xpos, yend = -1.2 * scale_info['a_radius'])
df <- tibble(x = x_pos, y = 0, xend = x2_pos, yend = -1.2 * scale_info['a_radius'])
} else {
df <- tibble(x = x_pos, y = 0, xend = x_pos, yend = -1)
}
Expand Down Expand Up @@ -377,7 +379,9 @@ gen_label_pos_4 <- function() {
prepare_venn_data <- function(data, columns = NULL,
show_elements = FALSE, show_percentage = TRUE, digits = 1,
label_sep = ",", count_column = NULL,
show_outside = "auto", auto_scale = FALSE) {
show_outside = c("auto", "none", "always"),
auto_scale = FALSE) {
show_outside <- match.arg(show_outside)
if (is.data.frame(data)) {
if (is.null(columns)) {
columns = data %>% select_if(is.logical) %>% names
Expand Down Expand Up @@ -521,7 +525,7 @@ prepare_venn_data <- function(data, columns = NULL,
} else {
stop("`data` should be either a list or a data.frame")
}
if ((show_outside == "none") || (show_outside == "auto" & df_text$n[[nrow(df_text)]] == 0)) {
if ((show_outside == "none") || (show_outside == "auto" && df_text$n[[nrow(df_text)]] == 0)) {
if (df_text$n[[nrow(df_text)]] > 0)
warning("Although not display in plot, outside elements are still count in percentages.")
df_text <- df_text[-nrow(df_text), ]
Expand Down
12 changes: 11 additions & 1 deletion R/globals.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
utils::globalVariables(c("theta", "x_raw", "y_raw",
"A", "B", "C", "D", "group",
"head", "hjust", "n", "text",
"vjust", "x", "y"))
"vjust", "x", "y",
"name", "xend", "yend",
"gen_element_df_2", "gen_element_df_3", "gen_element_df_4",
"gen_circle",
"calc_scale_info_2", "calc_scale_info_3", "calc_scale_info_4",
"min_overlap_for_text",
"gen_circle_2", "gen_circle_3", "gen_circle_4",
"gen_seg_pos_2", "gen_seg_pos_3", "gen_seg_pos_4",
"gen_label_pos_2", "gen_label_pos_3", "gen_label_pos_4",
"gen_text_pos_2", "gen_text_pos_3", "gen_text_pos_4",
"prepare_venn_data"))
6 changes: 6 additions & 0 deletions man/geom_venn.Rd

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

2 changes: 2 additions & 0 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 25fd3b5

Please sign in to comment.