Skip to content

Commit

Permalink
Suggest ggplot2 instead of import
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrerebeau committed Oct 19, 2023
1 parent 7834788 commit dfa39be
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 39 deletions.
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ BugReports: https://github.com/tesselle/dimensio/issues
Depends:
R (>= 3.5)
Imports:
ggplot2,
graphics,
grDevices,
methods,
rlang
methods
Suggests:
ggplot2,
khroma,
knitr,
rmarkdown,
Expand Down
20 changes: 0 additions & 20 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,6 @@ exportMethods(viz_variables)
exportMethods(wrap_confidence)
exportMethods(wrap_hull)
exportMethods(wrap_tolerance)
importFrom(ggplot2,Stat)
importFrom(ggplot2,aes)
importFrom(ggplot2,arrow)
importFrom(ggplot2,coord_fixed)
importFrom(ggplot2,geom_col)
importFrom(ggplot2,geom_hline)
importFrom(ggplot2,geom_line)
importFrom(ggplot2,geom_path)
importFrom(ggplot2,geom_point)
importFrom(ggplot2,geom_segment)
importFrom(ggplot2,geom_vline)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,ggproto)
importFrom(ggplot2,layer)
importFrom(ggplot2,scale_x_continuous)
importFrom(ggplot2,scale_x_discrete)
importFrom(ggplot2,scale_y_continuous)
importFrom(ggplot2,sec_axis)
importFrom(ggplot2,waiver)
importFrom(grDevices,adjustcolor)
importFrom(grDevices,chull)
importFrom(grDevices,colorRamp)
Expand All @@ -94,7 +75,6 @@ importFrom(methods,setMethod)
importFrom(methods,slot)
importFrom(methods,slotNames)
importFrom(methods,validObject)
importFrom(rlang,.data)
importFrom(stats,approx)
importFrom(stats,as.dist)
importFrom(stats,cov)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# dimensio 0.4.0.9000
## Bugfixes & changes
* Put `...` after required arguments.
* Suggest **ggplot2** instead of import.

## Enhancements
* `viz_individuals()`, `viz_row()`, `viz_variables()`, `viz_columns()` and `biplot()` gained new arguments allowing set the x and y limits of the plot.
Expand Down
42 changes: 31 additions & 11 deletions R/dimensio-deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,44 @@
#' @keywords internal
NULL

check_package <- function(x) {
if (!requireNamespace(x, quietly = TRUE)) {
msg <- "Package %s needed for this function to work. Please install it."
stop(sprintf(msg, x), call. = FALSE)
}
invisible(NULL)
}

# rlang ========================================================================
utils::globalVariables(".data")

# ggplot2 ======================================================================
# https://cran.r-project.org/web/packages/ggplot2/vignettes/extending-ggplot2.html

StatHull <- ggplot2::ggproto(
`_class` = "StatHull",
`_inherit` = ggplot2::Stat,
compute_group = function(data, scales) {
i <- chull(data$x, data$y)
data[c(i, i[1]), , drop = FALSE]
},
required_aes = c("x", "y")
)

#' @rdname dimensio-deprecated
#' @export
stat_hull <- function(mapping = NULL, data = NULL, geom = "polygon",
position = "identity", na.rm = FALSE, show.legend = NA,
inherit.aes = TRUE, ...) {
check_package("ggplot2")

StatHull <- ggplot2::ggproto(
`_class` = "StatHull",
`_inherit` = ggplot2::Stat,
compute_group = function(data, scales) {
i <- chull(data$x, data$y)
data[c(i, i[1]), , drop = FALSE]
},
required_aes = c("x", "y")
)

ggplot2::layer(
stat = StatHull, data = data, mapping = mapping, geom = geom,
position = position, show.legend = show.legend, inherit.aes = inherit.aes,
params = list(na.rm = na.rm, ...)
)
}


# Plot =========================================================================
## Rows ------------------------------------------------------------------------
#' @rdname dimensio-deprecated
Expand Down Expand Up @@ -134,6 +146,8 @@ setMethod(
alpha = NULL, colour = NULL, linetype = NULL,
size = NULL, group = NULL) {
.Deprecated(new = "viz_variables()", old = "plot_variables()")
check_package("ggplot2")

## Prepare data
data <- prepare_coord(object, margin = 2, axes = axes, active = active,
sup = sup, group = group)
Expand Down Expand Up @@ -222,6 +236,7 @@ setMethod(
definition = function(object, select = NULL, variance = TRUE, cumulative = TRUE,
fill = "grey30", border = "grey10", colour = "red") {
.Deprecated(new = "screeplot()", old = "plot_variance()")
check_package("ggplot2")

## Prepare data
data <- get_eigenvalues(object)
Expand Down Expand Up @@ -285,6 +300,8 @@ setMethod(
sort = TRUE, decreasing = TRUE, limit = 10,
fill = "grey30", border = "grey10") {
.Deprecated(new = "viz_contributions()", old = "plot_contributions()")
check_package("ggplot2")

## Prepare data
data <- prepare_contrib(
object,
Expand Down Expand Up @@ -328,6 +345,7 @@ setMethod(
sup = TRUE, sort = TRUE, decreasing = TRUE,
limit = 10, fill = "grey30", border = "grey10") {
.Deprecated(new = "viz_cos2()", old = "plot_cos2()")
check_package("ggplot2")

## Prepare data
data <- prepare_cos2(object, margin = margin, axes = axes,
Expand All @@ -354,6 +372,8 @@ setMethod(
plot_points <- function(object, margin, axes, active = TRUE, sup = TRUE,
alpha = NULL, colour = NULL, fill = NULL, shape = NULL,
size = NULL, group = NULL) {
check_package("ggplot2")

## Prepare data
data <- lapply(
X = margin,
Expand Down
1 change: 0 additions & 1 deletion R/dimensio-internal.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,3 @@ assert_length <- function(x, expected, empty = FALSE) {
}
invisible(x)
}

4 changes: 0 additions & 4 deletions R/dimensio-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,10 @@
#' @keywords internal
"_PACKAGE"

#' @importFrom ggplot2 aes arrow coord_fixed geom_col geom_hline geom_line
#' geom_path geom_point geom_segment geom_vline ggplot ggproto layer
#' scale_x_continuous scale_x_discrete scale_y_continuous sec_axis Stat waiver
#' @importFrom grDevices adjustcolor chull colorRamp hcl.colors rgb
#' @importFrom methods Arith as as<- callGeneric callNextMethod
#' .hasSlot initialize is new setClass setClassUnion
#' setGeneric setMethod slot slot<- slotNames validObject .valueClassTest
#' @importFrom rlang .data
#' @importFrom stats approx as.dist cov optim qchisq qf rmultinom
#' @importFrom utils capture.output stack tail
NULL
Expand Down

0 comments on commit dfa39be

Please sign in to comment.