Skip to content

Commit

Permalink
Address CRAN comments
Browse files Browse the repository at this point in the history
  • Loading branch information
const-ae committed Mar 1, 2019
1 parent 7fde865 commit 3476c6a
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 115 deletions.
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ URL: https://github.com/const-ae/ggupset
BugReports: https://github.com/const-ae/ggupset/issues
Authors@R: person("Constantin", "Ahlmann-Eltze", email = "[email protected]", role = c("aut", "cre"))
Description: Replace the standard x-axis in 'ggplots' with a combination matrix
to visualize complex set overlaps. UpSet has introduced a new way to visualize
the overlap of sets, this package provides a simple way to produce such plots
using ggplot. In addition it can convert any categorical axis into a combination
to visualize complex set overlaps. 'UpSet' has introduced a new way to visualize
the overlap of sets as an alternative to Venn diagrams.
This package provides a simple way to produce such plots using 'ggplot2'.
In addition it can convert any categorical axis into a combination
matrix axis.
License: GPL-3
Encoding: UTF-8
Expand Down
16 changes: 15 additions & 1 deletion R/scale_upset.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,24 @@
#' @param sep String the is used to delimit the elements in each list entry.
#' Default: "-".
#' @param ... additional arguments that are passed on to
#' \code{ggplot2::scale_discrete}
#' \code{ggplot2::scale_x_discrete}
#' @param position either "top" or "bottom" to specify where the
#' x axis drawn. Default: "bottom"
#'
#' @seealso \code{\link[ggplot2]{discrete_scale}}
#' @examples
#' library(ggplot2)
#' ggplot(tidy_movies[1:100, ], aes(x=Genres)) +
#' geom_bar() +
#' scale_x_mergelist() +
#' theme(axis.text.x = element_text(angle = 90, hjust=1, vjust = 0.5))
#'
#' ggplot(tidy_movies[1:100, ], aes(x=Genres)) +
#' geom_bar() +
#' scale_x_mergelist(sep = " & ", name = "Merged Movie Genres", position = "top") +
#' theme(axis.text.x = element_text(angle = 90, hjust=0, vjust = 0.5))
#'
#'
#' @export
scale_x_mergelist <- function(sep="-", ..., position = "bottom"){
sc <- discrete_scale(c("x", "xmin", "xmax", "xend"), "position_d", identity, ...,
Expand Down
19 changes: 19 additions & 0 deletions R/theme_combmatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@
#' Default: "#E0E0E0"
#' @param ... additional arguments that are passed to \code{theme()}
#'
#'
#' @examples
#' library(ggplot2)
#' # Ensure that the y-axis label is next to the axis by setting
#' # combmatrix.label.make_space to FALSE
#' ggplot(tidy_movies[1:100, ], aes(x=Genres)) +
#' geom_bar() +
#' scale_x_upset() +
#' theme_combmatrix(combmatrix.label.text = element_text(color = "black", size=15),
#' combmatrix.label.make_space = FALSE,
#' plot.margin = unit(c(1.5, 1.5, 1.5, 65), "pt"))
#'
#' # Change the color of the background stripes
#' ggplot(tidy_movies[1:100, ], aes(x=Genres)) +
#' geom_bar() +
#' scale_x_upset() +
#' theme_combmatrix(combmatrix.panel.striped_background = TRUE,
#' combmatrix.panel.striped_background.color.one = "grey")
#'
#' @export
theme_combmatrix <- function(
combmatrix.label.make_space = TRUE,
Expand Down
6 changes: 3 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Plot a combination matrix instead of the standard x-axis and create UpSet plots
You can install the released version of ggupset from [CRAN](https://CRAN.R-project.org) with:

``` r
# Package not yet on CRAN
# install.packages("ggupset")
# Download package from CRAN
install.packages("ggupset")

# Or get the latest version directly from GitHub
devtools::install_github("const-ae/ggupset")
Expand Down Expand Up @@ -211,7 +211,7 @@ df_complex_conditions %>%
geom_jitter(aes(color=KO), width=0.1) +
geom_smooth(method = "lm", aes(group = paste0(KO, "-", DrugA))) +
scale_x_upset(order_by = "degree",
levels=c("KO", "WT", "Drug", "8h", "24h", "48h"),
sets = c("KO", "WT", "Drug", "8h", "24h", "48h"),
position="top", name = "") +
theme_combmatrix(combmatrix.label.text = element_text(size=12),
combmatrix.label.extra_spacing = 5)
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Installation
You can install the released version of ggupset from [CRAN](https://CRAN.R-project.org) with:

``` r
# Package not yet on CRAN
# install.packages("ggupset")
# Download package from CRAN
install.packages("ggupset")

# Or get the latest version directly from GitHub
devtools::install_github("const-ae/ggupset")
Expand All @@ -29,12 +29,12 @@ This is a basic example which shows you how to solve a common problem:
# Load helper packages
library(ggplot2)
library(tidyverse)
#> ── Attaching packages ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
#> ── Attaching packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
#> ✔ tibble 1.4.2 ✔ purrr 0.2.5
#> ✔ tidyr 0.8.2 ✔ dplyr 0.7.8
#> ✔ readr 1.2.1 ✔ stringr 1.4.0
#> ✔ tibble 1.4.2 ✔ forcats 0.3.0
#> ── Conflicts ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
#> ── Conflicts ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
#> ✖ dplyr::filter() masks stats::filter()
#> ✖ dplyr::lag() masks stats::lag()

Expand Down Expand Up @@ -249,7 +249,7 @@ df_complex_conditions %>%
geom_jitter(aes(color=KO), width=0.1) +
geom_smooth(method = "lm", aes(group = paste0(KO, "-", DrugA))) +
scale_x_upset(order_by = "degree",
levels=c("KO", "WT", "Drug", "8h", "24h", "48h"),
sets = c("KO", "WT", "Drug", "8h", "24h", "48h"),
position="top", name = "") +
theme_combmatrix(combmatrix.label.text = element_text(size=12),
combmatrix.label.extra_spacing = 5)
Expand Down
10 changes: 10 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@

## Resubmission
This is a resubmission in this version I have:

* Put single quotes around 'ggplot2' and 'UpSet'

* Added examples to the documentation of `scale_x_mergelist()` and
`theme_combmatrix()`

* Added more automatic tests

## Test environments

* linux ubuntu: r 3.5.2
Expand Down
19 changes: 18 additions & 1 deletion man/scale_x_mergelist.Rd

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

19 changes: 19 additions & 0 deletions man/theme_combmatrix.Rd

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

152 changes: 50 additions & 102 deletions tests/testthat/test-axis_combmatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,122 +8,70 @@ test_that("Plotting works as expected", {
mtcars$comb <- paste0("gears: ", mtcars$gear, "-cyl: ", mtcars$cyl)
mtcars$list_col <- lapply(seq_len(nrow(mtcars)), function(idx) c(paste0("gear: ", mtcars$gear[idx]), paste0("cyl: ", mtcars$cyl[idx])))

expect_silent(
expect_silent({
ggplot(mtcars, aes(x=comb)) +
geom_bar() +
axis_combmatrix(sep="-")
)

ggplot(mtcars, aes(x=comb)) +
geom_bar() +
axis_combmatrix(sep="-")

ggplot(mtcars, aes(x=comb)) +
geom_bar() +
scale_x_discrete(position = "top") +
axis_combmatrix(sep="-")
ggplot(mtcars, aes(x=comb)) +
geom_bar() +
axis_combmatrix(sep="-")

ggplot(mtcars, aes(x=list_col)) +
geom_bar() +
scale_x_mergelist() +
axis_combmatrix(sep = "-")
ggplot(mtcars, aes(x=comb)) +
geom_bar() +
scale_x_discrete(position = "top") +
axis_combmatrix(sep="-")

ggplot(mtcars, aes(x=list_col)) +
geom_bar() +
scale_x_upset()
ggplot(mtcars, aes(x=list_col)) +
geom_bar() +
scale_x_mergelist() +
axis_combmatrix(sep = "-")

ggplot(mtcars, aes(x=list_col)) +
geom_bar() +
scale_x_upset(n_sets = 6)
ggplot(mtcars, aes(x=list_col)) +
geom_bar() +
scale_x_upset()

ggplot(mtcars, aes(x=list_col)) +
geom_bar() +
scale_x_upset(n_sets = 6)

ggplot(mtcars, aes(x=list_col)) +
geom_bar() +
scale_x_upset(intersections = list(c("gear: 3", "cyl: 8"), c("gear: 4", "cyl: 4"), c("cyl: 4", "gear: 3")))

ggplot(mtcars, aes(x=list_col)) +
geom_bar() +
scale_x_upset(intersections = list(c("gear: 3", "cyl: 8"), c("gear: 4", "cyl: 4"), c("cyl: 4", "gear: 3")))

ggplot(mtcars, aes(x=list_col)) +
geom_bar() +
scale_x_upset(n_intersections = 5)

ggplot(mtcars, aes(x=list_col)) +
geom_bar() +
scale_x_upset(n_intersections = 5, sets=c(paste0("gear: ", c(3,4,5)), paste0("cyl: ", c(4,6,8,9))))
ggplot(mtcars, aes(x=list_col)) +
geom_bar() +
scale_x_upset(n_intersections = 5)

ggplot(mtcars, aes(x=list_col)) +
geom_bar() +
scale_x_upset(n_intersections = 5, sets=c(paste0("gear: ", c(3,4,5)), paste0("cyl: ", c(4,6,8,9))))
})
})


# test_that("Test for skipping", {
# skip("Ignore")
# library(tidyverse)
#
# starwars %>%
# ggplot(aes(x=films)) +
# geom_bar() +
# scale_x_upset() +
# axis_combmatrix(sep = "-_-_-")
#
# starwars %>%
# mutate(films_col = map_chr(films, paste0, collapse="-")) %>%
# ggplot(aes(x=films)) +
# geom_bar() +
# axis_combmatrix(sep = "-")
#
#
# starwars %>%
# mutate(films_col = map_chr(films, paste0, collapse="-")) %>%
# ggplot(aes(x=films_col, y=height)) +
# geom_boxplot() +
# axis_combmatrix(sep = "-") +
# # theme(axis.text.x = element_text(angle = 90))
# NULL
#
# })
#
#
#
# test_that("Test for skipping 2", {
# skip("Ignore")
#
# library(ggplot2movies)
# library(tidyverse)
# tidy_movies <- movies %>%
# mutate(id = 1:n()) %>%
# gather(Genre, GenreMember, Action:Short) %>%
# filter(GenreMember == 1) %>%
# select(- GenreMember) %>%
# group_by_at(vars(-Genre)) %>%
# summarize(Genres = list(Genre)) %>%
# ungroup()
#
#
# tidy_movies %>%
# ggplot(aes(x=Genres)) +
# geom_bar() +
# scale_x_upset(n_intersections = 10)
#
# tidy_movies %>%
# sample_n(1000) %>%
# ggplot(aes(x=Genres)) +
# geom_bar() +
# scale_x_upset(n_intersections = 10)
#
# tidy_movies %>%
# sample_n(1000) %>%
# ggplot(aes(x=Genres, y=year)) +
# # geom_violin() +
# geom_boxplot() +
# scale_x_upset()
#
# tidy_movies %>%
# # sample_n(1000) %>%
# mutate(Genres_col = map_chr(Genres, ~ paste0(sort(.x), collapse="-"))) %>%
# mutate(Genres_col = fct_infreq(as.factor(Genres_col))) %>%
# mutate(Genres_col = fct_lump(Genres_col, n=12)) %>%
# ggplot(aes(x=Genres_col, y=year)) +
# geom_violin() +
# # geom_jitter(width = 0.1, height=0, size=0.01) +
# axis_combmatrix(sep="-", levels = c("Drama", "Comedy", "Short", "Documentary", "Action", "Romance"))
# NULL
#
# })

test_that("Plotting with tidy_movies works as expected 2", {
expect_silent({
ggplot(tidy_movies[1:100, ], aes(x=Genres)) +
geom_bar() +
scale_x_upset(n_intersections = 10)

ggplot(tidy_movies[1:100, ], aes(x=Genres)) +
geom_bar() +
scale_x_upset(n_intersections = 10)

ggplot(tidy_movies[1:100, ], aes(x=Genres, y=year)) +
geom_violin() +
scale_x_upset()

ggplot(tidy_movies[1:100, ], aes(x=sapply(Genres, paste0, collapse="-"), y=year)) +
geom_boxplot() +
geom_jitter(width = 0.1, height=0, size=1) +
axis_combmatrix(sep="-", levels = c("Drama", "Comedy", "Short", "Documentary", "Action", "Romance"))

})
})

0 comments on commit 3476c6a

Please sign in to comment.