Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of warnings and clean lints #267

Merged
merged 28 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
24ad910
Get rid of warnings about aes_string
IndrajeetPatil Jan 27, 2023
a207042
lints
IndrajeetPatil Jan 27, 2023
c79e56e
Update utils.R
IndrajeetPatil Jan 27, 2023
34d0e25
Use `#' @examplesIf` roxygen directive over `if()`
IndrajeetPatil Jan 29, 2023
71c131e
check class correctly
IndrajeetPatil Jan 29, 2023
ab8d99b
cleaning more lints
IndrajeetPatil Jan 29, 2023
466223e
Update geom_from_list.R
IndrajeetPatil Jan 29, 2023
39c8ea1
Merge branch 'main' into ggplot2_warnings
IndrajeetPatil Feb 3, 2023
57e13b5
use devel correlation
IndrajeetPatil Feb 3, 2023
eb9707a
suppress all rstan warnings
IndrajeetPatil Feb 3, 2023
506b18f
fix a few more warnings
IndrajeetPatil Feb 3, 2023
5165546
Update utils.R
IndrajeetPatil Feb 3, 2023
7c14cfe
use latest bayestestR
IndrajeetPatil Feb 4, 2023
cda4def
more dealing with warnings
IndrajeetPatil Feb 4, 2023
155668c
suppress rstanarm warnings in tests
IndrajeetPatil Feb 7, 2023
f452f44
fix more deprecations from ggplot2
IndrajeetPatil Feb 8, 2023
d27dd41
remove ggraph example
IndrajeetPatil Feb 9, 2023
bb38982
bump deps
IndrajeetPatil Feb 9, 2023
b31833d
warnings in examples
IndrajeetPatil Feb 9, 2023
85b0d40
remove NAs
IndrajeetPatil Feb 9, 2023
1a69bec
lintr
strengejacke Feb 14, 2023
50046f1
addressing more lints
IndrajeetPatil Feb 20, 2023
a046892
use more insight helpers
IndrajeetPatil Feb 21, 2023
4a1322a
more line length linter
IndrajeetPatil Feb 23, 2023
aa2b32a
glmmTMB is needed
IndrajeetPatil Feb 23, 2023
1c90ced
Merge branch 'main' into ggplot2_warnings
IndrajeetPatil Feb 27, 2023
0a87e56
Update utils.R
IndrajeetPatil Feb 28, 2023
eef61d3
Merge branch 'ggplot2_warnings' of https://github.com/easystats/see i…
IndrajeetPatil Feb 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,20 @@ Depends:
R (>= 3.6),
stats
Imports:
bayestestR (>= 0.13.0),
correlation (>= 0.8.3),
bayestestR (>= 0.13.0.6),
correlation (>= 0.8.3.1),
datawizard (>= 0.6.4),
effectsize (>= 0.8.2),
effectsize (>= 0.8.3),
ggplot2 (>= 3.4.0),
insight (>= 0.18.8),
insight (>= 0.19.0),
modelbased (>= 0.8.5),
parameters (>= 0.20.0),
performance (>= 0.10.1)
Remotes:
easystats/insight,
easystats/parameters,
easystats/correlation,
easystats/bayestestR
Suggests:
brms,
curl,
Expand Down
22 changes: 10 additions & 12 deletions R/coord_radar.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@
#' @inheritParams ggplot2::coord_polar
#' @param ... Other arguments to be passed to `ggproto`.
#'
#' @examples
#' @examplesIf require("datawizard") && require("ggplot2")
#' # Create a radar/spider chart with ggplot:
#' if (require("datawizard") && require("ggplot2")) {
#' data(iris)
#' data <- aggregate(iris[-5], list(Species = iris$Species), mean)
#' data <- data_to_long(
#' data,
#' c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")
#' )
#' data(iris)
#' data <- aggregate(iris[-5], list(Species = iris$Species), mean)
#' data <- data_to_long(
#' data,
#' c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width")
#' )
#'
#' ggplot(data, aes(x = name, y = value, color = Species, group = Species)) +
#' geom_polygon(fill = NA, linewidth = 2) +
#' coord_radar(start = -pi / 4)
#' }
#' ggplot(data, aes(x = name, y = value, color = Species, group = Species)) +
#' geom_polygon(fill = NA, linewidth = 2) +
#' coord_radar(start = -pi / 4)
#' @export
coord_radar <- function(theta = "x", start = 0, direction = 1, ...) {
theta <- match.arg(theta, c("x", "y"))
Expand Down
18 changes: 9 additions & 9 deletions R/data_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
#' library(bayestestR)
#' library(rstanarm)
#'
#' model <<- stan_glm(
#' model <<- suppressWarnings(stan_glm(
#' Sepal.Length ~ Petal.Width * Species,
#' data = iris,
#' chains = 2, iter = 200, refresh = 0
#' )
#' ))
#'
#' x <- rope(model)
#' x <- rope(model, verbose = FALSE)
#' plot(x)
#'
#' x <- hdi(model)
Expand All @@ -71,17 +71,17 @@
#' x <- p_direction(data)
#' plot(x)
#'
#' x <- p_direction(model)
#' x <- p_direction(model, verbose = FALSE)
#' plot(x)
#'
#' model <<- stan_glm(
#' model <<- suppressWarnings(stan_glm(
#' mpg ~ wt + gear + cyl + disp,
#' chains = 2,
#' iter = 200,
#' refresh = 0,
#' data = mtcars
#' )
#' x <- equivalence_test(model)
#' ))
#' x <- equivalence_test(model, verbose = FALSE)
#' plot(x)
#' @export
data_plot <- function(x, data = NULL, ...) {
Expand All @@ -104,11 +104,11 @@ data_plot <- function(x, data = NULL, ...) {
#' library(see)
#' library(ggplot2)
#'
#' model <- stan_glm(
#' model <- suppressWarnings(stan_glm(
#' Sepal.Length ~ Petal.Width + Species + Sepal.Width,
#' data = iris,
#' chains = 2, iter = 200
#' )
#' ))
#'
#' result <- hdi(model, ci = c(0.5, 0.75, 0.9, 0.95))
#' data <- data_plot(result, data = model)
Expand Down
42 changes: 10 additions & 32 deletions R/geom_from_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,6 @@
#' geom_from_list(list(aes = list(x = "Sepal.Length"), geom = "ggside::geom_xsidedensity")) +
#' geom_from_list(list(geom = "ggside::scale_xsidey_continuous", breaks = NULL))
#'
#' # Example 6 (ggraph) --------------------------
#'
#' @examplesIf require("tidygraph") && require("ggraph")
#' library(tidygraph)
#' library(ggraph)
#'
#' # Prepare graph
#' nodes <- data.frame(name = c("Death", "Famine", "War", "Conquest"))
#' edges <- data.frame(
#' from = c(1, 1, 1, 2, 3, 3, 4, 4, 4),
#' to = c(2, 3, 4, 1, 1, 2, 1, 2, 3)
#' )
#' data <- tidygraph::tbl_graph(nodes = nodes, edges = edges)
#'
#' ggraph(data, layout = "kk") +
#' geom_from_list(list(geom = "ggraph::geom_edge_arc")) +
#' geom_from_list(list(geom = "ggraph::geom_node_point", size = 10)) +
#' geom_from_list(list(geom = "ggraph::geom_node_label", aes = list(label = "name")))
#'
#' @export
geom_from_list <- function(x, ...) {
# Additional parameters ------------------------------------------------------
Expand Down Expand Up @@ -165,28 +146,25 @@ geom_from_list <- function(x, ...) {
return(do.call(ggplot2::facet_grid, args))
}
if (x$geom == "smooth") {
if (!is.null(x$aes)) args$mapping <- do.call(ggplot2::aes_string, x$aes)
if (!is.null(x$aes)) args$mapping <- do.call(ggplot2::aes, lapply(x$aes, .str_to_sym))
if (!"method" %in% names(args)) args$method <- "loess"
if (!"formula" %in% names(args)) args$formula <- "y ~ x"
return(do.call(ggplot2::geom_smooth, args))
}
if (startsWith(x$geom, "scale_")) {
return(do.call(x$geom, args))
}
if (startsWith(x$geom, "theme")) {
return(do.call(x$geom, args))
}
if (startsWith(x$geom, "see_")) {

if (startsWith(x$geom, "scale_") || startsWith(x$geom, "theme") || startsWith(x$geom, "see_")) {
return(do.call(x$geom, args))
}

if (startsWith(x$geom, "ggside::")) {
insight::check_if_installed("ggside")
if (!is.null(x$aes)) args$mapping <- do.call(ggplot2::aes_string, x$aes)
if (!is.null(x$aes)) args$mapping <- do.call(ggplot2::aes, lapply(x$aes, .str_to_sym))
return(do.call(eval(parse(text = x$geom)), args))
}

if (startsWith(x$geom, "ggraph::")) {
insight::check_if_installed("ggraph")
if (!is.null(x$aes)) args$mapping <- do.call(ggplot2::aes_string, x$aes)
if (!is.null(x$aes)) args$mapping <- do.call(ggplot2::aes, lapply(x$aes, .str_to_sym))
return(do.call(eval(parse(text = x$geom)), args))
}

Expand Down Expand Up @@ -214,11 +192,11 @@ geom_from_list <- function(x, ...) {
} else if (x$geom == "density_2d_polygon") {
stat <- ggplot2::StatDensity2d
x$geom <- "polygon"
if (!"fill" %in% names(x$aes)) x$aes$fill <- "..level.."
if (!"fill" %in% names(x$aes)) x$aes$fill <- quote(after_stat(level))
} else if (x$geom == "density_2d_raster") {
stat <- ggplot2::StatDensity2d
x$geom <- "raster"
if (!"fill" %in% names(x$aes)) x$aes$fill <- "..density.."
if (!"fill" %in% names(x$aes)) x$aes$fill <- quote(after_stat(density))
}

# Position
Expand All @@ -234,7 +212,7 @@ geom_from_list <- function(x, ...) {

# Aesthetics
if ("aes" %in% names(x)) {
aes_list <- do.call(ggplot2::aes_string, x$aes)
aes_list <- do.call(ggplot2::aes, lapply(x$aes, .str_to_sym))
} else {
aes_list <- NULL
}
Expand Down
63 changes: 47 additions & 16 deletions R/plot.check_distribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ plot.see_check_distribution <- function(x, size_point = 2, panel = TRUE, ...) {
dat <- data.frame(
x = factor(c(x$Distribution, x$Distribution), levels = rev(sort(unique(x$Distribution)))),
y = c(x$p_Response, x$p_Residuals),
group = factor(c(rep("Response", length(x$p_Response)), rep("Residuals", length(x$p_Residuals))),
group = factor(
c(rep("Response", length(x$p_Response)), rep("Residuals", length(x$p_Residuals))),
levels = c("Response", "Residuals")
),
stringsAsFactors = FALSE
Expand All @@ -39,16 +40,25 @@ plot.see_check_distribution <- function(x, size_point = 2, panel = TRUE, ...) {
# default legend-position
lp <- ifelse(isTRUE(panel), "right", "bottom")

p1 <- ggplot(dat, aes(
y = .data$x,
x = .data$y,
colour = .data$group
)) +
geom_linerange(aes(xmin = 0, xmax = .data$y),
p1 <- ggplot(
dat,
aes(
y = .data$x,
x = .data$y,
colour = .data$group
)
) +
geom_linerange(
aes(xmin = 0, xmax = .data$y),
position = position_dodge(0.4),
linewidth = 0.8
linewidth = 0.8,
na.rm = TRUE
) +
geom_point(
size = size_point,
position = position_dodge(0.4),
na.rm = TRUE
) +
geom_point(size = size_point, position = position_dodge(0.4)) +
labs(
y = NULL,
x = NULL,
Expand Down Expand Up @@ -91,7 +101,8 @@ plot.see_check_distribution <- function(x, size_point = 2, panel = TRUE, ...) {
p3 <- ggplot(dat2, aes(x = .data$x)) +
geom_histogram(
fill = "#f44336", colour = bar_color,
binwidth = sqrt(length(vars(.data$x)))
binwidth = sqrt(length(vars(.data$x))),
na.rm = TRUE
) +
labs(x = NULL, y = NULL, title = "Distribution of Response") +
theme_lucid()
Expand Down Expand Up @@ -130,10 +141,29 @@ plot.see_check_distribution_numeric <- function(x,
lp <- ifelse(isTRUE(panel), "right", "bottom")

p1 <- ggplot(dat, aes(y = .data$x, x = .data$y)) +
geom_linerange(aes(xmin = 0, xmax = .data$y), position = position_dodge(0.4), linewidth = 0.8) +
geom_point(size = size_point, position = position_dodge(0.4)) +
labs(y = NULL, x = NULL, fill = NULL, colour = NULL, title = "Predicted Distribution of Vector") +
scale_x_continuous(labels = .percents, expand = c(0, 0), limits = c(0, max_y)) +
geom_linerange(
aes(xmin = 0, xmax = .data$y),
position = position_dodge(0.4),
linewidth = 0.8,
na.rm = TRUE
) +
geom_point(
size = size_point,
position = position_dodge(0.4),
na.rm = TRUE
) +
labs(
y = NULL,
x = NULL,
fill = NULL,
colour = NULL,
title = "Predicted Distribution of Vector"
) +
scale_x_continuous(
labels = .percents,
expand = c(0, 0),
limits = c(0, max_y)
) +
theme_lucid(legend.position = lp)

dat1 <- as.data.frame(stats::density(vec))
Expand All @@ -147,14 +177,15 @@ plot.see_check_distribution_numeric <- function(x,
p3 <- ggplot(dat2, aes(x = .data$x)) +
geom_histogram(
colour = theme_lucid()$panel.background$fill,
binwidth = sqrt(length(vars(.data$x)))
binwidth = sqrt(length(vars(.data$x))),
na.rm = TRUE
) +
labs(x = NULL, y = NULL, title = "Distribution of Vector") +
theme_lucid()

if (panel) {
insight::check_if_installed("patchwork")
return(p1 / (p2 | p3) + patchwork::plot_layout(nrow = 2))
return(p1 / (p2 | p3) + patchwork::plot_layout(nrow = 2L))
} else {
return(list(p1, p2, p3))
}
Expand Down
20 changes: 16 additions & 4 deletions R/plot.check_homogeneity.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,21 @@ plot.see_check_homogeneity <- function(x, data = NULL, ...) {
ggrepel::geom_label_repel(
aes(label = .data$group),
y = 0, fill = "white",
data = data.frame(group = unique(dat$group)),
data = data.frame(
group = unique(dat$group),
stringsAsFactors = FALSE
),
direction = "y",
segment.colour = NA
)
} else {
geom_label(
aes(label = .data$group),
y = 0, fill = "white",
data = data.frame(group = unique(dat$group))
data = data.frame(
group = unique(dat$group),
stringsAsFactors = FALSE
)
)
}
} else {
Expand All @@ -84,15 +90,21 @@ plot.see_check_homogeneity <- function(x, data = NULL, ...) {
ggrepel::geom_label_repel(
aes(label = .data$x),
y = 0, fill = "white",
data = data.frame(x = unique(dat$x)),
data = data.frame(
x = unique(dat$x),
stringsAsFactors = FALSE
),
direction = "y",
segment.colour = NA
)
} else {
geom_label(
aes(label = .data$x),
y = 0, fill = "white",
data = data.frame(x = unique(dat$x))
data = data.frame(
x = unique(dat$x),
stringsAsFactors = FALSE
)
)
}
}
Expand Down
Loading