From f1f097e1f9eaf1eb701a4f109a34be19f3bd3721 Mon Sep 17 00:00:00 2001 From: DanielWang2029 <71171076+DanielWang2029@users.noreply.github.com> Date: Thu, 17 Dec 2020 22:47:17 +0800 Subject: [PATCH 01/18] Create test-dw.R Added dw test --- tests/testthat/test-dw.R | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/testthat/test-dw.R diff --git a/tests/testthat/test-dw.R b/tests/testthat/test-dw.R new file mode 100644 index 0000000..7f049e2 --- /dev/null +++ b/tests/testthat/test-dw.R @@ -0,0 +1,15 @@ +context("test-dw") +library(rlang) +library(tidyverse) +library(vdiffr) + +test_that("plots have known output", { + # disp_hist_base <- function() hist(mtcars$disp) + # expect_doppelganger("disp-histogram-base", disp_hist_base) + + # disp_hist_ggplot <- ggplot(mtcars, aes(disp)) + geom_histogram() + # expect_doppelganger("disp-histogram-ggplot", disp_hist_ggplot) + + mpg_plot <- ggplot(mtcars) + geom_bloc(aes(x = c(mpg), height = c(P(mpg | cyl)), y = c(cyl), fill = cyl)) + expect_doppelganger("mpg_plot", mpg_plot) +}) From 5f48c0120a96734dca2e8ad1d08394c99284ce30 Mon Sep 17 00:00:00 2001 From: DanielWang2029 <71171076+DanielWang2029@users.noreply.github.com> Date: Thu, 17 Dec 2020 22:50:27 +0800 Subject: [PATCH 02/18] Add files via upload Added codes I wrote to understand test_that and vdiffr --- tests/selftest.Rmd | 75 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tests/selftest.Rmd diff --git a/tests/selftest.Rmd b/tests/selftest.Rmd new file mode 100644 index 0000000..da18d2d --- /dev/null +++ b/tests/selftest.Rmd @@ -0,0 +1,75 @@ +--- +title: "Untitled" +author: "Daniel Wang" +date: "11/11/2020" +output: html_document +--- + +```{r} +devtools::load_all(".") +library(tidyverse) +library(ggplot2) +# library(pgog) +data(mpg) +ggplot(mtcars) + + geom_bloc(aes(x = c(mpg), height = c(P(mpg | cyl)), y = c(cyl), fill = cyl)) +``` + + +```{r} +library(testthat) +usethis::use_testthat() +library(stringr) + +test_that("str_length is number of characters", { + expect_equal(str_length("a"), 1) + expect_equal(str_length("ab"), 2) + expect_equal(str_length("abc"), 3) +}) + +string <- "Testing is fun!" +test_that("tests for string", {expect_match(string, "Testing") +expect_match(string, "testing") +expect_match(string, "testing", ignore.case = TRUE)}) +``` + + +```{r} +test_that("parsing things connect to ggplot", { +obj <- ggplot(mtcars) + + geom_bloc(aes(x = c(mpg), height = c(P(mpg | cyl)), y = c(cyl), fill = cyl)) +expect_null(obj) +}) +``` + +```{r} +data(cancer) + +disp_x_height <- cancer %>% + ggplot() + + geom_icon(aes(x = factor(test), + height = P(cancer), + color = cancer, + size = 10 + ), position = "array") +vdiffr::expect_doppelganger("x = A, height = P(A), array", disp_x_height) + +rlang::last_error() +``` + +```{r} +vdiffr::manage_cases() +``` +```{r} +test_that("plots have known output", { + # disp_hist_base <- function() hist(mtcars$disp) + # expect_doppelganger("disp-histogram-base", disp_hist_base) + + # disp_hist_ggplot <- ggplot(mtcars, aes(disp)) + geom_histogram() + # expect_doppelganger("disp-histogram-ggplot", disp_hist_ggplot) + + mpg_plot <- ggplot(mtcars) + geom_bloc(aes(x = c(mpg), height = c(P(mpg | cyl)), y = c(cyl), fill = cyl)) + expect_doppelganger("mpg_plot", mpg_plot) +}) +``` + From f1e7087f7410824bb543cba603754d1c2e957f43 Mon Sep 17 00:00:00 2001 From: DanielWang2029 <71171076+DanielWang2029@users.noreply.github.com> Date: Thu, 17 Dec 2020 23:18:30 +0800 Subject: [PATCH 03/18] Add files via upload Added svg plot for validation --- tests/figs/test-dw/mpg-plot.svg | 72 +++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tests/figs/test-dw/mpg-plot.svg diff --git a/tests/figs/test-dw/mpg-plot.svg b/tests/figs/test-dw/mpg-plot.svg new file mode 100644 index 0000000..66da721 --- /dev/null +++ b/tests/figs/test-dw/mpg-plot.svg @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + +4 +6 +8 +10 + + + + + + + + + + +10 +15 +20 +25 +30 +35 +x +y + + +4 +5 +6 +7 +8 +cyl + + + + + + + + + + +mpg_plot + From 7d2f032d44b76fefe07f7f190942f96a2251ef01 Mon Sep 17 00:00:00 2001 From: DanielWang2029 <71171076+DanielWang2029@users.noreply.github.com> Date: Thu, 17 Dec 2020 23:29:00 +0800 Subject: [PATCH 04/18] Update test-dw.R Changed variable names in test --- tests/testthat/test-dw.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-dw.R b/tests/testthat/test-dw.R index 7f049e2..9cba906 100644 --- a/tests/testthat/test-dw.R +++ b/tests/testthat/test-dw.R @@ -3,13 +3,13 @@ library(rlang) library(tidyverse) library(vdiffr) -test_that("plots have known output", { +test_that("test for the order of the plot", { # disp_hist_base <- function() hist(mtcars$disp) # expect_doppelganger("disp-histogram-base", disp_hist_base) # disp_hist_ggplot <- ggplot(mtcars, aes(disp)) + geom_histogram() # expect_doppelganger("disp-histogram-ggplot", disp_hist_ggplot) - mpg_plot <- ggplot(mtcars) + geom_bloc(aes(x = c(mpg), height = c(P(mpg | cyl)), y = c(cyl), fill = cyl)) - expect_doppelganger("mpg_plot", mpg_plot) + color_order_plot <- ggplot(mtcars) + geom_bloc(aes(x = c(mpg), height = c(P(mpg | cyl)), y = c(cyl), fill = cyl)) + expect_doppelganger("mpg_plot", color_order_plot) }) From 677947d6fdce39c79627107cb4cd5491eff86914 Mon Sep 17 00:00:00 2001 From: DanielWang2029 <71171076+DanielWang2029@users.noreply.github.com> Date: Thu, 17 Dec 2020 23:32:35 +0800 Subject: [PATCH 05/18] Add files via upload Added new test file, need to delete old test file --- tests/testthat/test-fill-order.R | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/testthat/test-fill-order.R diff --git a/tests/testthat/test-fill-order.R b/tests/testthat/test-fill-order.R new file mode 100644 index 0000000..ae1892f --- /dev/null +++ b/tests/testthat/test-fill-order.R @@ -0,0 +1,15 @@ +context("test-dw") +library(rlang) +library(tidyverse) +library(vdiffr) + +test_that("plots have known output", { + # disp_hist_base <- function() hist(mtcars$disp) + # expect_doppelganger("disp-histogram-base", disp_hist_base) + + # disp_hist_ggplot <- ggplot(mtcars, aes(disp)) + geom_histogram() + # expect_doppelganger("disp-histogram-ggplot", disp_hist_ggplot) + + fill_order_plot <- ggplot(mtcars) + geom_bloc(aes(x = c(mpg), height = c(P(mpg | cyl)), y = c(cyl), fill = cyl)) + expect_doppelganger("fill_order_plot", fill_order_plot) +}) From cdc61b3f933f6eb6c8d37c587dc4ae1c13becc14 Mon Sep 17 00:00:00 2001 From: DanielWang2029 <71171076+DanielWang2029@users.noreply.github.com> Date: Wed, 20 Jan 2021 22:25:51 +0800 Subject: [PATCH 06/18] Add algorithm.r algorithm.r contains a function that returns the arrangment of icons given the canvas size and icon numbers. --- algorithm.R | 139 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 algorithm.R diff --git a/algorithm.R b/algorithm.R new file mode 100644 index 0000000..54c9610 --- /dev/null +++ b/algorithm.R @@ -0,0 +1,139 @@ +# CanvasLength: the length of the canvas in numeric +# CanvasHeight: the height of the canvas in numeric +# NumberOfIcon: number of icon for each group in vector +# NumberOfGroup: number of groups in integer, default 1 +# connected: whether different groups of icon is connected in boolean, default false +arrangement = function(CanvasLength, CanvasHeight, NumberOfIcon, NumberOfGroups=1, connected=FALSE) { + + # color vector + color = c("blue", "green", "yellow", "red", "gray") + + # return empty list if one of height, length and number of groups is invalid + if (CanvasHeight <= 0 || CanvasLength <= 0 || NumberOfGroups <= 0) { + return(list()) + } + + # return empty list if number of icon does not match number of groups + if (length(NumberOfIcon) != NumberOfGroups) { + return(list()) + } + + # return empty list if number of icon is invalid + for (x in NumberOfIcon) { + if (x <= 0) { + return(list()) + } + } + + # return empty list if more than 5 colors are needed + if (NumberOfGroups > 5) { + return(list()) + } + + # swap height and length then make the recursive call if height is larger than length + if (CanvasHeight > CanvasLength) { + result = arrangement(CanvasHeight, CanvasLength, NumberOfIcon, NumberOfGroups, connected) + for (i in seq(1, length(result))) { + temp = result[[i]][1] + result[[i]][1] = result[[i]][2] + result[[i]][2] = temp + } + return(result) + } + + if (NumberOfGroups == 1) { + + # case 1: only one group + NumberOfIcon = NumberOfIcon[1] + + # simply return the center of the canvas if there's onlyh one icon + if (NumberOfIcon == 1) { + return(list(c(CanvasLength / 2, CanvasHeight / 2, color[1]))) + } + + # create a vector holding the differences between the length and height of icon for different icon arrangements + differences = c() + for (i in seq(ceiling(sqrt(NumberOfIcon)), NumberOfIcon)) { + differences = c(differences, abs(CanvasHeight / ceiling(NumberOfIcon / i) - CanvasLength / i)) + } + + # choose the arrangement that has the smallest differences in icon length and height + iconPerLine = which(differences == min(differences))[1] + iconPerLine = iconPerLine + ceiling(sqrt(NumberOfIcon)) - 1 + iconSizeHorizontal = CanvasLength / iconPerLine + iconSizeVertical = CanvasHeight / ceiling(NumberOfIcon / iconPerLine) + + # create list to return using the selected arrangement + x = 1 + y = 1 + index = 1 + result = list() + while(index <= NumberOfIcon) { + result[[index]] = c((x - 1/2) * iconSizeHorizontal, (y - 1/2) * iconSizeVertical, color[1]) + index = index + 1 + x = x + 1 + if (x > iconPerLine) { + x = 1 + y = y + 1 + } + } + return(result) + + } else { + + # case 2: multiple group but connected + if (connected) { + + # recursive call as if all groups are one large group + result = arrangement(CanvasLength, CanvasHeight, c(sum(NumberOfIcon)), 1, FALSE) + + # change colors in the return value above to make sure different group has different color + index = NumberOfIcon[1] + for (i in seq(2, NumberOfGroups)) { + for (j in seq(1, NumberOfIcon[i])) { + result[[index + j]][3] = color[i] + } + index = index + NumberOfIcon[i] + } + return(result) + + } else { + + # case 3: multiple group not connected + # create a vector holding the differences between the length and height of icon for different icon arrangements + differences = c() + for (i in seq(1, max(NumberOfIcon))) { + iconHolderPerLine = sum(ceiling(NumberOfIcon / i)) + NumberOfGroups - 1 + differences = c(differences, abs(CanvasHeight / i - CanvasLength / iconHolderPerLine)) + } + + # choose the arrangement that has the smallest differences in icon length and height + iconHolderPerVerticalLine = which(differences == min(differences))[1] + iconSizeVertical = CanvasHeight / iconHolderPerVerticalLine + iconSizeHorizontal = CanvasLength / (sum(ceiling(NumberOfIcon / iconHolderPerVerticalLine)) + NumberOfGroups - 1) + + # create list to return using the selected arrangement + x = 1 + y = 0 + index = 0 + result = list() + for (i in seq(1, NumberOfGroups)) { + for (j in seq(1, NumberOfIcon[i])) { + index = index + 1 + y = y + 1 + if (y > iconHolderPerVerticalLine) { + x = x + 1 + y = 1 + } + result[[index]] = c((x - 1/2) * iconSizeHorizontal, (y - 1/2) * iconSizeVertical, color[i]) + } + x = x + 2 + y = 0 + } + return(result) + } + } + + # return empty list if the code fails somehow + return(list()) +} From f3f7fdffe6a4ec20dd754d32f2bb09570d7a330c Mon Sep 17 00:00:00 2001 From: DanielWang2029 <71171076+DanielWang2029@users.noreply.github.com> Date: Tue, 9 Feb 2021 22:54:07 +0800 Subject: [PATCH 07/18] Update geom-icon.R Updated algorithm and part of makeContent function --- R/geom-icon.R | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) diff --git a/R/geom-icon.R b/R/geom-icon.R index 6582857..714c480 100644 --- a/R/geom-icon.R +++ b/R/geom-icon.R @@ -1,3 +1,171 @@ +icon_grob = function(data, num_of_icon, num_of_group, connected, + name = NULL, gp = gpar(), vp = NULL) { + + gTree( + data = data, num_of_icon = num_of_icon, num_of_group = num_of_group, connected = connected, + name = name, gp = gp, vp = vp, cl = "icon_grob" + ) +} + +makeContent.icon_grob = function(x) { + data = x$data + canvas_height = convertUnit(unit(1, 'npc'), 'native', valueOnly = TRUE) + canvas_length = convertUnit(unit(0, 'npc'), 'native', axisFrom = "y", valueOnly = TRUE) + num_of_icon = x$num_of_icon + num_of_group = x$num_of_group + connected = x$connected + + result = arrangement(canvas_length, canvas_height, NumberOfIcon = num_of_icon, + NumberOfGroups = num_of_group, connected = connected) + + +} + + + + +# CanvasLength: the length of the canvas in numeric +# CanvasHeight: the height of the canvas in numeric +# NumberOfIcon: number of icon for each group in vector +# NumberOfGroup: number of groups in integer, default 1 +# connected: whether different groups of icon is connected in boolean, default false +arrangement = function(CanvasLength, CanvasHeight, NumberOfIcon, NumberOfGroups=1, connected=FALSE) { + + # color vector + color = c("blue", "green", "yellow", "red", "gray") + + # return empty list if one of height, length and number of groups is invalid + if (CanvasHeight <= 0 || CanvasLength <= 0 || NumberOfGroups <= 0) { + return(list()) + } + + # return empty list if number of icon does not match number of groups + if (length(NumberOfIcon) != NumberOfGroups) { + return(list()) + } + + # return empty list if number of icon is invalid + for (x in NumberOfIcon) { + if (x <= 0) { + return(list()) + } + } + + # return empty list if more than 5 colors are needed + if (NumberOfGroups > 5) { + return(list()) + } + + # swap height and length then make the recursive call if height is larger than length + if (CanvasHeight > CanvasLength) { + result = arrangement(CanvasHeight, CanvasLength, NumberOfIcon, NumberOfGroups, connected) + for (i in seq(1, length(result))) { + temp = result[[i]][1] + result[[i]][1] = result[[i]][2] + result[[i]][2] = temp + } + return(result) + } + + if (NumberOfGroups == 1) { + + # case 1: only one group + NumberOfIcon = NumberOfIcon[1] + + # simply return the center of the canvas if there's onlyh one icon + if (NumberOfIcon == 1) { + return(list(c(CanvasLength / 2, CanvasHeight / 2, color[1]))) + } + + # create a vector holding the differences between the length and height of icon for different icon arrangements + differences = c() + for (i in seq(ceiling(sqrt(NumberOfIcon)), NumberOfIcon)) { + differences = c(differences, abs(CanvasHeight / ceiling(NumberOfIcon / i) - CanvasLength / i)) + } + + # choose the arrangement that has the smallest differences in icon length and height + iconPerLine = which(differences == min(differences))[1] + iconPerLine = iconPerLine + ceiling(sqrt(NumberOfIcon)) - 1 + iconSizeHorizontal = CanvasLength / iconPerLine + iconSizeVertical = CanvasHeight / ceiling(NumberOfIcon / iconPerLine) + + # create list to return using the selected arrangement + x = 1 + y = 1 + index = 1 + result = list() + while(index <= NumberOfIcon) { + result[[index]] = c((x - 1/2) * iconSizeHorizontal, (y - 1/2) * iconSizeVertical, color[1]) + index = index + 1 + x = x + 1 + if (x > iconPerLine) { + x = 1 + y = y + 1 + } + } + return(result) + + } else { + + # case 2: multiple group but connected + if (connected) { + + # recursive call as if all groups are one large group + result = arrangement(CanvasLength, CanvasHeight, c(sum(NumberOfIcon)), 1, FALSE) + + # change colors in the return value above to make sure different group has different color + index = NumberOfIcon[1] + for (i in seq(2, NumberOfGroups)) { + for (j in seq(1, NumberOfIcon[i])) { + result[[index + j]][3] = color[i] + } + index = index + NumberOfIcon[i] + } + return(result) + + } else { + + # case 3: multiple group not connected + # create a vector holding the differences between the length and height of icon for different icon arrangements + differences = c() + for (i in seq(1, max(NumberOfIcon))) { + iconHolderPerLine = sum(ceiling(NumberOfIcon / i)) + NumberOfGroups - 1 + differences = c(differences, abs(CanvasHeight / i - CanvasLength / iconHolderPerLine)) + } + + # choose the arrangement that has the smallest differences in icon length and height + iconHolderPerVerticalLine = which(differences == min(differences))[1] + iconSizeVertical = CanvasHeight / iconHolderPerVerticalLine + iconSizeHorizontal = CanvasLength / (sum(ceiling(NumberOfIcon / iconHolderPerVerticalLine)) + NumberOfGroups - 1) + + # create list to return using the selected arrangement + x = 1 + y = 0 + index = 0 + result = list() + for (i in seq(1, NumberOfGroups)) { + for (j in seq(1, NumberOfIcon[i])) { + index = index + 1 + y = y + 1 + if (y > iconHolderPerVerticalLine) { + x = x + 1 + y = 1 + } + result[[index]] = c((x - 1/2) * iconSizeHorizontal, (y - 1/2) * iconSizeVertical, color[i]) + } + x = x + 2 + y = 0 + } + return(result) + } + } + + # return empty list if the code fails somehow + return(list()) +} + + + #' @export geom_icon <- function(mapping = NULL, From 594c5df32eb5be436254b8cbfa183d3200ca5185 Mon Sep 17 00:00:00 2001 From: DanielWang2029 <71171076+DanielWang2029@users.noreply.github.com> Date: Tue, 9 Feb 2021 22:57:46 +0800 Subject: [PATCH 08/18] Update geom-bloc.R Updated solution for the first issue --- R/geom-bloc.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/R/geom-bloc.R b/R/geom-bloc.R index 013e711..6e51978 100644 --- a/R/geom-bloc.R +++ b/R/geom-bloc.R @@ -126,6 +126,16 @@ GeomBloc <- ggplot2::ggproto( # from ggplot, geom-ribbon.r setup_data = function(self, data, params){ #browser() + + new.data = data.frame(data) + grp.level = levels(as.factor(data$group)) + grp = list() + for (i in seq(length(grp.level))) { + grp[[i]] = which(data$group == as.numeric(grp.level[i])) + new.data[grp[[i]], ]$group = as.numeric(grp.level[length(grp.level) - i + 1]) + } + data = new.data + if ("density" %in% names(data)) { #browser() # all density plots From cb55dac7d7a911928324663179ecccb42ed0102b Mon Sep 17 00:00:00 2001 From: DanielWang2029 <71171076+DanielWang2029@users.noreply.github.com> Date: Thu, 4 Nov 2021 07:43:47 -0500 Subject: [PATCH 09/18] Update geom-bloc.R --- R/geom-bloc.R | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/R/geom-bloc.R b/R/geom-bloc.R index 6e51978..9baddac 100644 --- a/R/geom-bloc.R +++ b/R/geom-bloc.R @@ -127,6 +127,17 @@ GeomBloc <- ggplot2::ggproto( setup_data = function(self, data, params){ #browser() + # fill.level = levels(as.factor(data$fill)) + # rows = list() + # new.data = data.frame() + # copy.data = data.frame(data) + # for (i in seq(length(fill.level), 1, -1)) { + # rows[[i]] = which(data$fill == fill.level[i]) + # copy.data[rows[[i]], ]$fill = as.numeric(fill.level[length(fill.level) - i + 1]) + # new.data = rbind(new.data, copy.data[rows[[i]], ]) + # } + # data = new.data + new.data = data.frame(data) grp.level = levels(as.factor(data$group)) grp = list() From fb3352ea4b4c166f2cf5517255c52b38b3dfd257 Mon Sep 17 00:00:00 2001 From: DanielWang2029 <71171076+DanielWang2029@users.noreply.github.com> Date: Thu, 4 Nov 2021 07:45:05 -0500 Subject: [PATCH 10/18] Update geom-icon.R --- R/geom-icon.R | 126 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 92 insertions(+), 34 deletions(-) diff --git a/R/geom-icon.R b/R/geom-icon.R index 714c480..03aeb65 100644 --- a/R/geom-icon.R +++ b/R/geom-icon.R @@ -1,35 +1,9 @@ -icon_grob = function(data, num_of_icon, num_of_group, connected, - name = NULL, gp = gpar(), vp = NULL) { - - gTree( - data = data, num_of_icon = num_of_icon, num_of_group = num_of_group, connected = connected, - name = name, gp = gp, vp = vp, cl = "icon_grob" - ) -} - -makeContent.icon_grob = function(x) { - data = x$data - canvas_height = convertUnit(unit(1, 'npc'), 'native', valueOnly = TRUE) - canvas_length = convertUnit(unit(0, 'npc'), 'native', axisFrom = "y", valueOnly = TRUE) - num_of_icon = x$num_of_icon - num_of_group = x$num_of_group - connected = x$connected - - result = arrangement(canvas_length, canvas_height, NumberOfIcon = num_of_icon, - NumberOfGroups = num_of_group, connected = connected) - - -} - - - - # CanvasLength: the length of the canvas in numeric # CanvasHeight: the height of the canvas in numeric # NumberOfIcon: number of icon for each group in vector # NumberOfGroup: number of groups in integer, default 1 # connected: whether different groups of icon is connected in boolean, default false -arrangement = function(CanvasLength, CanvasHeight, NumberOfIcon, NumberOfGroups=1, connected=FALSE) { +arrangement = function(CanvasLength, CanvasHeight, NumberOfIcon, NumberOfGroups=1, connected=FALSE, ratio=1.0) { # color vector color = c("blue", "green", "yellow", "red", "gray") @@ -58,7 +32,7 @@ arrangement = function(CanvasLength, CanvasHeight, NumberOfIcon, NumberOfGroups= # swap height and length then make the recursive call if height is larger than length if (CanvasHeight > CanvasLength) { - result = arrangement(CanvasHeight, CanvasLength, NumberOfIcon, NumberOfGroups, connected) + result = arrangement(CanvasHeight, CanvasLength, NumberOfIcon, NumberOfGroups, connected, ratio) for (i in seq(1, length(result))) { temp = result[[i]][1] result[[i]][1] = result[[i]][2] @@ -88,6 +62,7 @@ arrangement = function(CanvasLength, CanvasHeight, NumberOfIcon, NumberOfGroups= iconPerLine = iconPerLine + ceiling(sqrt(NumberOfIcon)) - 1 iconSizeHorizontal = CanvasLength / iconPerLine iconSizeVertical = CanvasHeight / ceiling(NumberOfIcon / iconPerLine) + iconSize = min(c(iconSizeVertical, iconSizeHorizontal)) * ratio # create list to return using the selected arrangement x = 1 @@ -95,7 +70,7 @@ arrangement = function(CanvasLength, CanvasHeight, NumberOfIcon, NumberOfGroups= index = 1 result = list() while(index <= NumberOfIcon) { - result[[index]] = c((x - 1/2) * iconSizeHorizontal, (y - 1/2) * iconSizeVertical, color[1]) + result[[index]] = c((x - 1/2) * iconSizeHorizontal, (y - 1/2) * iconSizeVertical, color[1], iconSize) index = index + 1 x = x + 1 if (x > iconPerLine) { @@ -111,7 +86,7 @@ arrangement = function(CanvasLength, CanvasHeight, NumberOfIcon, NumberOfGroups= if (connected) { # recursive call as if all groups are one large group - result = arrangement(CanvasLength, CanvasHeight, c(sum(NumberOfIcon)), 1, FALSE) + result = arrangement(CanvasLength, CanvasHeight, c(sum(NumberOfIcon)), 1, FALSE, ratio) # change colors in the return value above to make sure different group has different color index = NumberOfIcon[1] @@ -137,6 +112,7 @@ arrangement = function(CanvasLength, CanvasHeight, NumberOfIcon, NumberOfGroups= iconHolderPerVerticalLine = which(differences == min(differences))[1] iconSizeVertical = CanvasHeight / iconHolderPerVerticalLine iconSizeHorizontal = CanvasLength / (sum(ceiling(NumberOfIcon / iconHolderPerVerticalLine)) + NumberOfGroups - 1) + iconSize = min(c(iconSizeVertical, iconSizeHorizontal)) * ratio # create list to return using the selected arrangement x = 1 @@ -151,7 +127,7 @@ arrangement = function(CanvasLength, CanvasHeight, NumberOfIcon, NumberOfGroups= x = x + 1 y = 1 } - result[[index]] = c((x - 1/2) * iconSizeHorizontal, (y - 1/2) * iconSizeVertical, color[i]) + result[[index]] = c((x - 1/2) * iconSizeHorizontal, (y - 1/2) * iconSizeVertical, color[i], iconSize) } x = x + 2 y = 0 @@ -164,7 +140,52 @@ arrangement = function(CanvasLength, CanvasHeight, NumberOfIcon, NumberOfGroups= return(list()) } +icon_grob = function(data, num_of_icon, num_of_group, connected, canvas_length, canvas_height, ratio, + name = NULL, gp = gpar(), vp = NULL) { + + gTree( + data = data, num_of_icon = num_of_icon, num_of_group = num_of_group, connected = connected, + canvas_length = canvas_length, canvas_height = canvas_height, ratio = ratio, name = name, gp = gp, vp = vp, cl = "icon_grob" + ) +} + +#' @import grid +#' @export +makeContent.icon_grob = function(x) { + + # browser() + # print(1 / convertUnit(unit(1, 'inches'), 'native', valueOnly = TRUE)) + # print(1 / convertUnit(unit(1, 'inches'), 'native', axisFrom = "y", valueOnly = TRUE)) + data = x$data + canvas_length = 1 / convertUnit(unit(1, 'inches'), 'native', valueOnly = TRUE) + canvas_height = 1 / convertUnit(unit(1, 'inches'), 'native', axisFrom = "y", valueOnly = TRUE) + # canvas_length = convertUnit(unit(1, 'npc'), 'native', valueOnly = TRUE) + # canvas_height = convertUnit(unit(0, 'npc'), 'native', axisFrom = "y", valueOnly = TRUE) + num_of_icon = x$num_of_icon + num_of_group = x$num_of_group + connected = x$connected + + result = arrangement(canvas_length, canvas_height, NumberOfIcon = num_of_icon, + NumberOfGroups = num_of_group, connected = connected, x$ratio) + + x_vals = c() + y_vals = c() + cols = c() + for (i in seq(length(result))) + { + x_vals = append(x_vals, as.double(result[[i]][1]) / canvas_length) + y_vals = append(y_vals, as.double(result[[i]][2]) / canvas_height) + cols = append(cols, result[[i]][3]) + } + + grobSize = as.double(result[[1]][4]) / 2 / canvas_height + # print(x_vals) + # print(y_vals) + # print(grobSize) + + circleGrob(x_vals, y_vals, grobSize, default.units = "native", gp = x$gp) +} #' @export @@ -178,7 +199,8 @@ geom_icon <- function(mapping = NULL, show.legend = NA, inherit.aes = TRUE, offset = 0.01, - prob.struct = NULL){ + prob.struct = NULL + ){ # same as in geom_bloc # parse prob structure @@ -232,17 +254,53 @@ geom_icon <- function(mapping = NULL, #' @importFrom grid pointsGrob #' @importFrom grid gpar #' @importFrom ggplot2 aes -GeomIcon <- ggplot2::ggproto("GeomIcon", ggplot2::GeomPoint, +GeomIcon <- ggplot2::ggproto("GeomIcon", ggplot2::Geom, required_aes = c("x", "y"), non_missing_aes = c("size", "shape", "colour"), default_aes = ggplot2::aes( shape = 16, colour = "gray", size = 10, fill = NA, - alpha = NA, stroke = 0.5 + alpha = NA, stroke = 0.5, ratio = 1.0 ), setup_data = function(data, params) { #browser() data + }, + + draw_panel = function(self, data, panel_params, coord, na.rm = FALSE) { + coords <- coord$transform(data, panel_params) + str(coords) + + # assuming the first row of the data is cyl + vec = unlist(coords[1]) + + # browser() + + canvas_length = convertUnit(unit(1, 'npc'), 'native', valueOnly = TRUE) + canvas_height = convertUnit(unit(0, 'npc'), 'native', axisFrom = "y", valueOnly = TRUE) + + group_input = length(levels(as.factor(vec))) + icon_input = rep(0, length(levels(as.factor(vec)))) + for (i in seq(length(levels(as.factor(vec))))) { + icon_input[i] = length(which(vec == as.numeric(levels(vec)[i]))) + } + + result = arrangement(canvas_length, canvas_height, NumberOfIcon = icon_input, + NumberOfGroups = group_input, connected = FALSE, ratio = coords$ratio[1]) + + x_vals = c() + y_vals = c() + cols = c() + for (i in seq(length(result))) + { + x_vals = append(x_vals, as.double(result[[i]][1]) / canvas_length) + y_vals = append(y_vals, as.double(result[[i]][2]) / canvas_height) + cols = append(cols, result[[i]][3]) + } + + # pointsGrob(x_vals, y_vals, default.units = "native", gp = gpar(col = cols, lwd = 2)) + icon_grob(data = vec, num_of_icon = icon_input, num_of_group = group_input, + connected = FALSE, canvas_length, canvas_height, coords$ratio[1], gp = gpar(fill = cols)) } From e60a20ef31a44b5c40d2d8767c27ecd8a70d9a03 Mon Sep 17 00:00:00 2001 From: DanielWang2029 <71171076+DanielWang2029@users.noreply.github.com> Date: Thu, 4 Nov 2021 07:45:55 -0500 Subject: [PATCH 11/18] Update NAMESPACE --- NAMESPACE | 1 + 1 file changed, 1 insertion(+) diff --git a/NAMESPACE b/NAMESPACE index 7e568ce..d4d1459 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,6 @@ # Generated by roxygen2: do not edit by hand +S3method(makeContent,icon_grob) export(GeomIcon) export(ddecker) export(geom_bloc) From 01106f7db380b3fafdeedb00f00441d673360b09 Mon Sep 17 00:00:00 2001 From: DanielWang2029 <71171076+DanielWang2029@users.noreply.github.com> Date: Thu, 4 Nov 2021 07:57:14 -0500 Subject: [PATCH 12/18] Update geom-bloc.R --- R/geom-bloc.R | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/R/geom-bloc.R b/R/geom-bloc.R index 9baddac..4068e3b 100644 --- a/R/geom-bloc.R +++ b/R/geom-bloc.R @@ -127,26 +127,6 @@ GeomBloc <- ggplot2::ggproto( setup_data = function(self, data, params){ #browser() - # fill.level = levels(as.factor(data$fill)) - # rows = list() - # new.data = data.frame() - # copy.data = data.frame(data) - # for (i in seq(length(fill.level), 1, -1)) { - # rows[[i]] = which(data$fill == fill.level[i]) - # copy.data[rows[[i]], ]$fill = as.numeric(fill.level[length(fill.level) - i + 1]) - # new.data = rbind(new.data, copy.data[rows[[i]], ]) - # } - # data = new.data - - new.data = data.frame(data) - grp.level = levels(as.factor(data$group)) - grp = list() - for (i in seq(length(grp.level))) { - grp[[i]] = which(data$group == as.numeric(grp.level[i])) - new.data[grp[[i]], ]$group = as.numeric(grp.level[length(grp.level) - i + 1]) - } - data = new.data - if ("density" %in% names(data)) { #browser() # all density plots From 0f1751ee22c348d36a06f6342f8dad1c53136b0f Mon Sep 17 00:00:00 2001 From: Xiaoying Pu Date: Tue, 9 Nov 2021 19:41:27 -0500 Subject: [PATCH 13/18] not sure why eol is messed up, for issue #98 --- algorithm.R | 278 +++++++++++++++---------------- tests/selftest.Rmd | 150 ++++++++--------- tests/testthat/test-fill-order.R | 30 ++-- 3 files changed, 229 insertions(+), 229 deletions(-) diff --git a/algorithm.R b/algorithm.R index 54c9610..f96ba2c 100644 --- a/algorithm.R +++ b/algorithm.R @@ -1,139 +1,139 @@ -# CanvasLength: the length of the canvas in numeric -# CanvasHeight: the height of the canvas in numeric -# NumberOfIcon: number of icon for each group in vector -# NumberOfGroup: number of groups in integer, default 1 -# connected: whether different groups of icon is connected in boolean, default false -arrangement = function(CanvasLength, CanvasHeight, NumberOfIcon, NumberOfGroups=1, connected=FALSE) { - - # color vector - color = c("blue", "green", "yellow", "red", "gray") - - # return empty list if one of height, length and number of groups is invalid - if (CanvasHeight <= 0 || CanvasLength <= 0 || NumberOfGroups <= 0) { - return(list()) - } - - # return empty list if number of icon does not match number of groups - if (length(NumberOfIcon) != NumberOfGroups) { - return(list()) - } - - # return empty list if number of icon is invalid - for (x in NumberOfIcon) { - if (x <= 0) { - return(list()) - } - } - - # return empty list if more than 5 colors are needed - if (NumberOfGroups > 5) { - return(list()) - } - - # swap height and length then make the recursive call if height is larger than length - if (CanvasHeight > CanvasLength) { - result = arrangement(CanvasHeight, CanvasLength, NumberOfIcon, NumberOfGroups, connected) - for (i in seq(1, length(result))) { - temp = result[[i]][1] - result[[i]][1] = result[[i]][2] - result[[i]][2] = temp - } - return(result) - } - - if (NumberOfGroups == 1) { - - # case 1: only one group - NumberOfIcon = NumberOfIcon[1] - - # simply return the center of the canvas if there's onlyh one icon - if (NumberOfIcon == 1) { - return(list(c(CanvasLength / 2, CanvasHeight / 2, color[1]))) - } - - # create a vector holding the differences between the length and height of icon for different icon arrangements - differences = c() - for (i in seq(ceiling(sqrt(NumberOfIcon)), NumberOfIcon)) { - differences = c(differences, abs(CanvasHeight / ceiling(NumberOfIcon / i) - CanvasLength / i)) - } - - # choose the arrangement that has the smallest differences in icon length and height - iconPerLine = which(differences == min(differences))[1] - iconPerLine = iconPerLine + ceiling(sqrt(NumberOfIcon)) - 1 - iconSizeHorizontal = CanvasLength / iconPerLine - iconSizeVertical = CanvasHeight / ceiling(NumberOfIcon / iconPerLine) - - # create list to return using the selected arrangement - x = 1 - y = 1 - index = 1 - result = list() - while(index <= NumberOfIcon) { - result[[index]] = c((x - 1/2) * iconSizeHorizontal, (y - 1/2) * iconSizeVertical, color[1]) - index = index + 1 - x = x + 1 - if (x > iconPerLine) { - x = 1 - y = y + 1 - } - } - return(result) - - } else { - - # case 2: multiple group but connected - if (connected) { - - # recursive call as if all groups are one large group - result = arrangement(CanvasLength, CanvasHeight, c(sum(NumberOfIcon)), 1, FALSE) - - # change colors in the return value above to make sure different group has different color - index = NumberOfIcon[1] - for (i in seq(2, NumberOfGroups)) { - for (j in seq(1, NumberOfIcon[i])) { - result[[index + j]][3] = color[i] - } - index = index + NumberOfIcon[i] - } - return(result) - - } else { - - # case 3: multiple group not connected - # create a vector holding the differences between the length and height of icon for different icon arrangements - differences = c() - for (i in seq(1, max(NumberOfIcon))) { - iconHolderPerLine = sum(ceiling(NumberOfIcon / i)) + NumberOfGroups - 1 - differences = c(differences, abs(CanvasHeight / i - CanvasLength / iconHolderPerLine)) - } - - # choose the arrangement that has the smallest differences in icon length and height - iconHolderPerVerticalLine = which(differences == min(differences))[1] - iconSizeVertical = CanvasHeight / iconHolderPerVerticalLine - iconSizeHorizontal = CanvasLength / (sum(ceiling(NumberOfIcon / iconHolderPerVerticalLine)) + NumberOfGroups - 1) - - # create list to return using the selected arrangement - x = 1 - y = 0 - index = 0 - result = list() - for (i in seq(1, NumberOfGroups)) { - for (j in seq(1, NumberOfIcon[i])) { - index = index + 1 - y = y + 1 - if (y > iconHolderPerVerticalLine) { - x = x + 1 - y = 1 - } - result[[index]] = c((x - 1/2) * iconSizeHorizontal, (y - 1/2) * iconSizeVertical, color[i]) - } - x = x + 2 - y = 0 - } - return(result) - } - } - - # return empty list if the code fails somehow - return(list()) -} +# CanvasLength: the length of the canvas in numeric +# CanvasHeight: the height of the canvas in numeric +# NumberOfIcon: number of icon for each group in vector +# NumberOfGroup: number of groups in integer, default 1 +# connected: whether different groups of icon is connected in boolean, default false +arrangement = function(CanvasLength, CanvasHeight, NumberOfIcon, NumberOfGroups=1, connected=FALSE) { + + # color vector + color = c("blue", "green", "yellow", "red", "gray") + + # return empty list if one of height, length and number of groups is invalid + if (CanvasHeight <= 0 || CanvasLength <= 0 || NumberOfGroups <= 0) { + return(list()) + } + + # return empty list if number of icon does not match number of groups + if (length(NumberOfIcon) != NumberOfGroups) { + return(list()) + } + + # return empty list if number of icon is invalid + for (x in NumberOfIcon) { + if (x <= 0) { + return(list()) + } + } + + # return empty list if more than 5 colors are needed + if (NumberOfGroups > 5) { + return(list()) + } + + # swap height and length then make the recursive call if height is larger than length + if (CanvasHeight > CanvasLength) { + result = arrangement(CanvasHeight, CanvasLength, NumberOfIcon, NumberOfGroups, connected) + for (i in seq(1, length(result))) { + temp = result[[i]][1] + result[[i]][1] = result[[i]][2] + result[[i]][2] = temp + } + return(result) + } + + if (NumberOfGroups == 1) { + + # case 1: only one group + NumberOfIcon = NumberOfIcon[1] + + # simply return the center of the canvas if there's onlyh one icon + if (NumberOfIcon == 1) { + return(list(c(CanvasLength / 2, CanvasHeight / 2, color[1]))) + } + + # create a vector holding the differences between the length and height of icon for different icon arrangements + differences = c() + for (i in seq(ceiling(sqrt(NumberOfIcon)), NumberOfIcon)) { + differences = c(differences, abs(CanvasHeight / ceiling(NumberOfIcon / i) - CanvasLength / i)) + } + + # choose the arrangement that has the smallest differences in icon length and height + iconPerLine = which(differences == min(differences))[1] + iconPerLine = iconPerLine + ceiling(sqrt(NumberOfIcon)) - 1 + iconSizeHorizontal = CanvasLength / iconPerLine + iconSizeVertical = CanvasHeight / ceiling(NumberOfIcon / iconPerLine) + + # create list to return using the selected arrangement + x = 1 + y = 1 + index = 1 + result = list() + while(index <= NumberOfIcon) { + result[[index]] = c((x - 1/2) * iconSizeHorizontal, (y - 1/2) * iconSizeVertical, color[1]) + index = index + 1 + x = x + 1 + if (x > iconPerLine) { + x = 1 + y = y + 1 + } + } + return(result) + + } else { + + # case 2: multiple group but connected + if (connected) { + + # recursive call as if all groups are one large group + result = arrangement(CanvasLength, CanvasHeight, c(sum(NumberOfIcon)), 1, FALSE) + + # change colors in the return value above to make sure different group has different color + index = NumberOfIcon[1] + for (i in seq(2, NumberOfGroups)) { + for (j in seq(1, NumberOfIcon[i])) { + result[[index + j]][3] = color[i] + } + index = index + NumberOfIcon[i] + } + return(result) + + } else { + + # case 3: multiple group not connected + # create a vector holding the differences between the length and height of icon for different icon arrangements + differences = c() + for (i in seq(1, max(NumberOfIcon))) { + iconHolderPerLine = sum(ceiling(NumberOfIcon / i)) + NumberOfGroups - 1 + differences = c(differences, abs(CanvasHeight / i - CanvasLength / iconHolderPerLine)) + } + + # choose the arrangement that has the smallest differences in icon length and height + iconHolderPerVerticalLine = which(differences == min(differences))[1] + iconSizeVertical = CanvasHeight / iconHolderPerVerticalLine + iconSizeHorizontal = CanvasLength / (sum(ceiling(NumberOfIcon / iconHolderPerVerticalLine)) + NumberOfGroups - 1) + + # create list to return using the selected arrangement + x = 1 + y = 0 + index = 0 + result = list() + for (i in seq(1, NumberOfGroups)) { + for (j in seq(1, NumberOfIcon[i])) { + index = index + 1 + y = y + 1 + if (y > iconHolderPerVerticalLine) { + x = x + 1 + y = 1 + } + result[[index]] = c((x - 1/2) * iconSizeHorizontal, (y - 1/2) * iconSizeVertical, color[i]) + } + x = x + 2 + y = 0 + } + return(result) + } + } + + # return empty list if the code fails somehow + return(list()) +} diff --git a/tests/selftest.Rmd b/tests/selftest.Rmd index da18d2d..174e807 100644 --- a/tests/selftest.Rmd +++ b/tests/selftest.Rmd @@ -1,75 +1,75 @@ ---- -title: "Untitled" -author: "Daniel Wang" -date: "11/11/2020" -output: html_document ---- - -```{r} -devtools::load_all(".") -library(tidyverse) -library(ggplot2) -# library(pgog) -data(mpg) -ggplot(mtcars) + - geom_bloc(aes(x = c(mpg), height = c(P(mpg | cyl)), y = c(cyl), fill = cyl)) -``` - - -```{r} -library(testthat) -usethis::use_testthat() -library(stringr) - -test_that("str_length is number of characters", { - expect_equal(str_length("a"), 1) - expect_equal(str_length("ab"), 2) - expect_equal(str_length("abc"), 3) -}) - -string <- "Testing is fun!" -test_that("tests for string", {expect_match(string, "Testing") -expect_match(string, "testing") -expect_match(string, "testing", ignore.case = TRUE)}) -``` - - -```{r} -test_that("parsing things connect to ggplot", { -obj <- ggplot(mtcars) + - geom_bloc(aes(x = c(mpg), height = c(P(mpg | cyl)), y = c(cyl), fill = cyl)) -expect_null(obj) -}) -``` - -```{r} -data(cancer) - -disp_x_height <- cancer %>% - ggplot() + - geom_icon(aes(x = factor(test), - height = P(cancer), - color = cancer, - size = 10 - ), position = "array") -vdiffr::expect_doppelganger("x = A, height = P(A), array", disp_x_height) - -rlang::last_error() -``` - -```{r} -vdiffr::manage_cases() -``` -```{r} -test_that("plots have known output", { - # disp_hist_base <- function() hist(mtcars$disp) - # expect_doppelganger("disp-histogram-base", disp_hist_base) - - # disp_hist_ggplot <- ggplot(mtcars, aes(disp)) + geom_histogram() - # expect_doppelganger("disp-histogram-ggplot", disp_hist_ggplot) - - mpg_plot <- ggplot(mtcars) + geom_bloc(aes(x = c(mpg), height = c(P(mpg | cyl)), y = c(cyl), fill = cyl)) - expect_doppelganger("mpg_plot", mpg_plot) -}) -``` - +--- +title: "Untitled" +author: "Daniel Wang" +date: "11/11/2020" +output: html_document +--- + +```{r} +devtools::load_all(".") +library(tidyverse) +library(ggplot2) +# library(pgog) +data(mpg) +ggplot(mtcars) + + geom_bloc(aes(x = c(mpg), height = c(P(mpg | cyl)), y = c(cyl), fill = cyl)) +``` + + +```{r} +library(testthat) +usethis::use_testthat() +library(stringr) + +test_that("str_length is number of characters", { + expect_equal(str_length("a"), 1) + expect_equal(str_length("ab"), 2) + expect_equal(str_length("abc"), 3) +}) + +string <- "Testing is fun!" +test_that("tests for string", {expect_match(string, "Testing") +expect_match(string, "testing") +expect_match(string, "testing", ignore.case = TRUE)}) +``` + + +```{r} +test_that("parsing things connect to ggplot", { +obj <- ggplot(mtcars) + + geom_bloc(aes(x = c(mpg), height = c(P(mpg | cyl)), y = c(cyl), fill = cyl)) +expect_null(obj) +}) +``` + +```{r} +data(cancer) + +disp_x_height <- cancer %>% + ggplot() + + geom_icon(aes(x = factor(test), + height = P(cancer), + color = cancer, + size = 10 + ), position = "array") +vdiffr::expect_doppelganger("x = A, height = P(A), array", disp_x_height) + +rlang::last_error() +``` + +```{r} +vdiffr::manage_cases() +``` +```{r} +test_that("plots have known output", { + # disp_hist_base <- function() hist(mtcars$disp) + # expect_doppelganger("disp-histogram-base", disp_hist_base) + + # disp_hist_ggplot <- ggplot(mtcars, aes(disp)) + geom_histogram() + # expect_doppelganger("disp-histogram-ggplot", disp_hist_ggplot) + + mpg_plot <- ggplot(mtcars) + geom_bloc(aes(x = c(mpg), height = c(P(mpg | cyl)), y = c(cyl), fill = cyl)) + expect_doppelganger("mpg_plot", mpg_plot) +}) +``` + diff --git a/tests/testthat/test-fill-order.R b/tests/testthat/test-fill-order.R index ae1892f..9afbd42 100644 --- a/tests/testthat/test-fill-order.R +++ b/tests/testthat/test-fill-order.R @@ -1,15 +1,15 @@ -context("test-dw") -library(rlang) -library(tidyverse) -library(vdiffr) - -test_that("plots have known output", { - # disp_hist_base <- function() hist(mtcars$disp) - # expect_doppelganger("disp-histogram-base", disp_hist_base) - - # disp_hist_ggplot <- ggplot(mtcars, aes(disp)) + geom_histogram() - # expect_doppelganger("disp-histogram-ggplot", disp_hist_ggplot) - - fill_order_plot <- ggplot(mtcars) + geom_bloc(aes(x = c(mpg), height = c(P(mpg | cyl)), y = c(cyl), fill = cyl)) - expect_doppelganger("fill_order_plot", fill_order_plot) -}) +context("test-dw") +library(rlang) +library(tidyverse) +library(vdiffr) + +test_that("plots have known output", { + # disp_hist_base <- function() hist(mtcars$disp) + # expect_doppelganger("disp-histogram-base", disp_hist_base) + + # disp_hist_ggplot <- ggplot(mtcars, aes(disp)) + geom_histogram() + # expect_doppelganger("disp-histogram-ggplot", disp_hist_ggplot) + + fill_order_plot <- ggplot(mtcars) + geom_bloc(aes(x = c(mpg), height = c(P(mpg | cyl)), y = c(cyl), fill = cyl)) + expect_doppelganger("fill_order_plot", fill_order_plot) +}) From 8e2846ab3123b4a50da53b3467caead33dc442b8 Mon Sep 17 00:00:00 2001 From: Xiaoying Pu Date: Tue, 9 Nov 2021 20:05:24 -0500 Subject: [PATCH 14/18] #98 fixed makeContent export --- DESCRIPTION | 2 +- NAMESPACE | 2 ++ R/geom-icon.R | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index fcdb981..9b2c6b2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -7,7 +7,7 @@ Depends: R (>= 3.5.0) License: What license is it under? Encoding: UTF-8 LazyData: true -RoxygenNote: 7.1.0 +RoxygenNote: 7.1.1 Imports: tidyverse, ggplot2, grid, diff --git a/NAMESPACE b/NAMESPACE index d4d1459..6e00479 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,12 +7,14 @@ export(geom_bloc) export(geom_icon) export(hbar) export(hspine) +export(makeContent.icon_grob) export(mosaic) export(parse_aes) export(spine) export(vbar) export(vspine) import(dplyr) +import(grid) import(rlang) importFrom(dplyr,filter) importFrom(dplyr,intersect) diff --git a/R/geom-icon.R b/R/geom-icon.R index 03aeb65..db2db0e 100644 --- a/R/geom-icon.R +++ b/R/geom-icon.R @@ -150,6 +150,7 @@ icon_grob = function(data, num_of_icon, num_of_group, connected, canvas_length, } #' @import grid +#' @export makeContent.icon_grob #' @export makeContent.icon_grob = function(x) { From 93419c20df185058b97bf70db844e5e9022bd609 Mon Sep 17 00:00:00 2001 From: Xiaoying Pu Date: Tue, 9 Nov 2021 22:50:05 -0500 Subject: [PATCH 15/18] #98 trigger the new action --- vignettes/pgog.Rmd | 1 - 1 file changed, 1 deletion(-) diff --git a/vignettes/pgog.Rmd b/vignettes/pgog.Rmd index e553b36..cee7d2b 100644 --- a/vignettes/pgog.Rmd +++ b/vignettes/pgog.Rmd @@ -53,7 +53,6 @@ colorbrewer2 <- rev(c( "#0868ac", "#084081")) - colorbrewer2_warm <- rev(c( "#ffffb2", "#fecc5c", From e3a93f1af58bc899b23aaf5fc32e219fc3042b36 Mon Sep 17 00:00:00 2001 From: Xiaoying Pu Date: Thu, 2 Dec 2021 10:48:08 -0500 Subject: [PATCH 16/18] removed extra @export --- NAMESPACE | 1 - R/geom-icon.R | 1 - 2 files changed, 2 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 6e00479..7aa2e18 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,7 +7,6 @@ export(geom_bloc) export(geom_icon) export(hbar) export(hspine) -export(makeContent.icon_grob) export(mosaic) export(parse_aes) export(spine) diff --git a/R/geom-icon.R b/R/geom-icon.R index db2db0e..03aeb65 100644 --- a/R/geom-icon.R +++ b/R/geom-icon.R @@ -150,7 +150,6 @@ icon_grob = function(data, num_of_icon, num_of_group, connected, canvas_length, } #' @import grid -#' @export makeContent.icon_grob #' @export makeContent.icon_grob = function(x) { From 3aa517f88541eccb54ff9ad69bfdce10769555a4 Mon Sep 17 00:00:00 2001 From: Xiaoying Pu Date: Thu, 2 Dec 2021 10:48:08 -0500 Subject: [PATCH 17/18] removed extra @export #98 --- NAMESPACE | 1 - R/geom-icon.R | 1 - 2 files changed, 2 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 6e00479..7aa2e18 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,7 +7,6 @@ export(geom_bloc) export(geom_icon) export(hbar) export(hspine) -export(makeContent.icon_grob) export(mosaic) export(parse_aes) export(spine) diff --git a/R/geom-icon.R b/R/geom-icon.R index db2db0e..03aeb65 100644 --- a/R/geom-icon.R +++ b/R/geom-icon.R @@ -150,7 +150,6 @@ icon_grob = function(data, num_of_icon, num_of_group, connected, canvas_length, } #' @import grid -#' @export makeContent.icon_grob #' @export makeContent.icon_grob = function(x) { From 2ea29fe2eaf9d1433bb28f1ecaed00088974e292 Mon Sep 17 00:00:00 2001 From: Xiaoying Pu Date: Fri, 8 Jul 2022 15:02:36 -0400 Subject: [PATCH 18/18] test commit --- R/geom-icon.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/geom-icon.R b/R/geom-icon.R index 03aeb65..5c5359f 100644 --- a/R/geom-icon.R +++ b/R/geom-icon.R @@ -153,7 +153,6 @@ icon_grob = function(data, num_of_icon, num_of_group, connected, canvas_length, #' @export makeContent.icon_grob = function(x) { - # browser() # print(1 / convertUnit(unit(1, 'inches'), 'native', valueOnly = TRUE)) # print(1 / convertUnit(unit(1, 'inches'), 'native', axisFrom = "y", valueOnly = TRUE)) data = x$data