diff --git a/DESCRIPTION b/DESCRIPTION index eeaac9b..cfb1a75 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: ggpmisc Type: Package Title: Miscellaneous Extensions to 'ggplot2' Version: 0.5.6.9003 -Date: 2024-05-26 +Date: 2024-06-01 Authors@R: c( person("Pedro J.", "Aphalo", email = "pedro.aphalo@helsinki.fi", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-3385-972X")), diff --git a/NEWS.md b/NEWS.md index 8a6f8af..def9004 100644 --- a/NEWS.md +++ b/NEWS.md @@ -14,6 +14,7 @@ editor_options: - Export the new utility functions now used internally for formatting parameter estimates into character strings in `stat_poly_eq()`, `stat_ma_eq()`, `stat_quant_eq()`, `stat_correlation()`, and `stat_multcomp()`. - Implement R options `ggpmisc.small.p`, `ggpmisc.small.r` and `ggpmisc.decreasing.poly.eq`. - Allow user-defined fit methods passed as argument to `stat_poly_eq()`, `stat_poly_line()`, `stat_ma_eq()`, `stat_ma_line()`, `stat_quant_eq()`, `stat_quant_line()`, and `stat_quant_band()` to return an atomic `NA` or a length zero object to skip labelling or plotting related to the attempted model fit. +- Implement automatic switch to `output.type = "markdown"` for `geom = "marquee"`. # ggpmisc 0.5.6 diff --git a/R/stat-correlation.R b/R/stat-correlation.R index 9373e84..7a7188c 100644 --- a/R/stat-correlation.R +++ b/R/stat-correlation.R @@ -286,7 +286,7 @@ stat_correlation <- show.legend = FALSE, inherit.aes = TRUE) { if (is.null(output.type)) { - if (geom %in% c("richtext", "textbox")) { + if (geom %in% c("richtext", "textbox", "marquee")) { output.type <- "markdown" } else { output.type <- "expression" @@ -465,6 +465,7 @@ cor_test_compute_fun <- function(data, z[["n"]] <- nrow(na.omit(data[ , c("x", "y")])) z[["method"]] <- method z[["r.conf.level"]] <- conf.level + if (boot.R >= 50 && conf.level > 0) { confint.boot <- confintr::ci_cor(data[ , c("x", "y")], @@ -479,8 +480,8 @@ cor_test_compute_fun <- function(data, z[["r.confint.low"]] <- htest.ls[["conf.int"]][1] z[["r.confint.high"]] <- htest.ls[["conf.int"]][2] } else { - if (conf.level < 0) { - message("Skipping bootstrap estimation as 'conf.level' < 0") + if (conf.level <= 0) { + message("Skipping bootstrap estimation as 'conf.level' <= 0") } else if (boot.R > 0) { warning("Skipping bootstrap estimation as 'boot.R' < 50") } diff --git a/R/stat-ma-eq.R b/R/stat-ma-eq.R index 16b3e2f..0223528 100644 --- a/R/stat-ma-eq.R +++ b/R/stat-ma-eq.R @@ -356,7 +356,7 @@ stat_ma_eq <- function(mapping = NULL, data = NULL, } if (is.null(output.type)) { - if (geom %in% c("richtext", "textbox")) { + if (geom %in% c("richtext", "textbox", "marquee")) { output.type <- "markdown" } else { output.type <- "expression" diff --git a/R/stat-multcomp.R b/R/stat-multcomp.R index 5722f97..59da654 100644 --- a/R/stat-multcomp.R +++ b/R/stat-multcomp.R @@ -378,7 +378,7 @@ stat_multcomp <- function(mapping = NULL, data = NULL, } if (is.null(output.type)) { - if (geom %in% c("richtext", "textbox")) { + if (geom %in% c("richtext", "textbox", "marquee")) { output.type <- "markdown" } else { output.type <- "expression" diff --git a/R/stat-poly-eq.R b/R/stat-poly-eq.R index a1560f8..895df57 100644 --- a/R/stat-poly-eq.R +++ b/R/stat-poly-eq.R @@ -552,7 +552,7 @@ stat_poly_eq <- function(mapping = NULL, data = NULL, } if (is.null(output.type)) { - if (geom %in% c("richtext", "textbox")) { + if (geom %in% c("richtext", "textbox", "marquee")) { output.type <- "markdown" } else { output.type <- "expression" diff --git a/inst-not/GLM/GLM-in-stat-poly_line.R b/inst-not/GLM/GLM-in-stat-poly_line.R index 3a954ee..26f72f4 100644 --- a/inst-not/GLM/GLM-in-stat-poly_line.R +++ b/inst-not/GLM/GLM-in-stat-poly_line.R @@ -12,9 +12,23 @@ model <- glm(y ~ x, data = df, family = gaussian) ggplot(df, aes(x, y)) + geom_point() + - stat_poly_line(method = "glm", method.args = list(family = gaussian)) + + stat_poly_line(method = "lm", se = TRUE) + + stat_poly_eq(method = "lm") + +ggplot(df, aes(x, y)) + + geom_point() + + stat_poly_line(method = "glm", method.args = list(family = gaussian), se = FALSE) + + stat_poly_eq(use_label("eq"), method = "glm", method.args = list(family = gaussian)) + +ggplot(df, aes(x, y)) + + geom_point() + + stat_smooth(method = "glm", method.args = list(family = gaussian), se = TRUE) + stat_poly_eq(method = "glm", method.args = list(family = gaussian)) +ggplot(df, aes(x, y)) + + geom_point() + + stat_poly_line(method = "glm", method.args = list(family = gaussian), se = TRUE) + + stat_poly_eq(use_label("eq", "p"), method = "glm", method.args = list(family = gaussian)) # Poisson -> poisson ------------------------------------------------------ # example from https://stackoverflow.com/questions/69808033/how-can-i-create-a-ggplot-with-a-regression-line-based-on-the-predicted-values-o @@ -28,5 +42,10 @@ model <- glm(y ~ x, data = df, family = poisson) ggplot(df, aes(x, y)) + geom_point() + - stat_poly_line(method = "glm", method.args = list(family = poisson)) + + stat_poly_line(method = "glm", method.args = list(family = poisson), se = FALSE) + + stat_poly_eq(method = "glm", method.args = list(family = poisson)) + +ggplot(df, aes(x, y)) + + geom_point() + + stat_smooth(method = "glm", method.args = list(family = poisson), se = TRUE) + stat_poly_eq(method = "glm", method.args = list(family = poisson)) diff --git a/inst-not/quantreg/ggplo2-quantreg-rqss.R b/inst-not/quantreg/ggplo2-quantreg-rqss.R new file mode 100644 index 0000000..8b3cf3d --- /dev/null +++ b/inst-not/quantreg/ggplo2-quantreg-rqss.R @@ -0,0 +1,13 @@ +library(ggplot2) + +m <- + ggplot(mpg, aes(displ, 1 / hwy)) + + geom_point() +m + stat_quantile() + +m + stat_quantile(method = "rqss") + +m + stat_quantile(method = "rqss", lambda = 0.1) + +sessionInfo() + diff --git a/inst-not/quantreg/ggpmisc-quantreg-rqss.R b/inst-not/quantreg/ggpmisc-quantreg-rqss.R new file mode 100644 index 0000000..8247ca8 --- /dev/null +++ b/inst-not/quantreg/ggpmisc-quantreg-rqss.R @@ -0,0 +1,25 @@ +library(ggplot2) +library(ggpmisc) + +p <- + ggplot(mpg, aes(displ, 1 / hwy)) + + geom_point() +p + stat_quant_line() + +p + stat_quant_line(method = "rqss") + +p + stat_quant_line(method = "rqss", lambda = 0.1) + +p + stat_quant_band() + +p + stat_quant_band(method = "rqss") + +p + stat_quant_band(method = "rqss", lambda = 0.1) + +p + stat_quant_eq() + +p + stat_quant_eq(method = "rqss") + +p + stat_quant_eq(method = "rqss", lambda = 0.1) + +sessionInfo() diff --git a/inst-not/quantreg/quantreg-rqss-examples.R b/inst-not/quantreg/quantreg-rqss-examples.R new file mode 100644 index 0000000..3bc853f --- /dev/null +++ b/inst-not/quantreg/quantreg-rqss-examples.R @@ -0,0 +1,29 @@ +library(quantreg) + +n <- 200 +x <- sort(rchisq(n,4)) +z <- x + rnorm(n) +y <- log(x)+ .1*(log(x))^2 + log(x)*rnorm(n)/4 + z +plot(x, y-z) + +f.N <- rqss(y ~ qss(x, constraint= "N") + z) + +f.I <- rqss(y ~ qss(x, constraint= "I") + z) + +f.CI <- rqss(y ~ qss(x, constraint= "CI") + z) + +lines(x[-1], f.N $coef[1] + f.N $coef[-(1:2)]) + +lines(x[-1], f.I $coef[1] + f.I $coef[-(1:2)], col="blue") + +lines(x[-1], f.CI$coef[1] + f.CI$coef[-(1:2)], col="red") + +## A bivariate example +if(requireNamespace("interp")){ + if(requireNamespace("interp")){ + data(CobarOre) + fCO <- rqss(z ~ qss(cbind(x,y), lambda= .08), data=CobarOre) + plot(fCO) + }} + +sessionInfo() diff --git a/tests/testthat/_snaps/stat-quant-band/stat-quant-band-formula-missing-rqss.new.svg b/tests/testthat/_snaps/stat-quant-band/stat-quant-band-formula-missing-rqss.new.svg new file mode 100644 index 0000000..6964880 --- /dev/null +++ b/tests/testthat/_snaps/stat-quant-band/stat-quant-band-formula-missing-rqss.new.svg @@ -0,0 +1,157 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0 +30 +60 +90 +120 + + + + + + + + + + +0 +25 +50 +75 +100 +x +y +stat_quant_band_formula_missing_rqss + + diff --git a/tests/testthat/_snaps/stat-quant-line/stat-quant-line-formula-missing-rqss.new.svg b/tests/testthat/_snaps/stat-quant-line/stat-quant-line-formula-missing-rqss.new.svg new file mode 100644 index 0000000..36fd13f --- /dev/null +++ b/tests/testthat/_snaps/stat-quant-line/stat-quant-line-formula-missing-rqss.new.svg @@ -0,0 +1,157 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0 +30 +60 +90 +120 + + + + + + + + + + +0 +25 +50 +75 +100 +x +y +stat_quant_line_formula_missing_rqss + + diff --git a/tests/testthat/test-eq-label-utils.R b/tests/testthat/test-eq-label-utils.R index 0333c33..a87cdec 100644 --- a/tests/testthat/test-eq-label-utils.R +++ b/tests/testthat/test-eq-label-utils.R @@ -58,7 +58,7 @@ test_that("polynomial as character well formatted", { expect_equal(poly2character(x = (1:5) * 1e-6, decreasing = TRUE, digits = 3, keep.zeros = TRUE), "5.00e-06*x^4 + 4.00e-06*x^3 + 3.00e-06*x^2 + 2.00e-06*x + 1.00e-06") expect_equal(poly2character(x = (1:5) * 1e+3, decreasing = TRUE, digits = 3, keep.zeros = TRUE), - "5.00e+03*x^4 + 4.00e+03*x^3 + 3.00e+03*x^2 + 2.00e+03*x + 1.000e+03") + "5.00e+03*x^4 + 4.00e+03*x^3 + 3.00e+03*x^2 + 2.00e+03*x + 1.00e+03") expect_warning(poly2character(x = NA)) expect_true(is.na(suppressWarnings(poly2character(x = NA)))) expect_equal(poly2character(x = NULL), character(0)) diff --git a/vignettes/model-based-annotations.Rmd b/vignettes/model-based-annotations.Rmd index 83fd4a5..27a781e 100644 --- a/vignettes/model-based-annotations.Rmd +++ b/vignettes/model-based-annotations.Rmd @@ -1416,7 +1416,7 @@ Volcano and quadrant plots are scatter plots with some peculiarities. Creating t Manual scales for colour and fill aesthetics with defaults suitable for the three way outcomes from statistical tests. -### scale_x\_FDR, scale_y\_FDR, scale_x\_logFC, scale_y\_logFC, scale_x\_Pvalue, scale_y\_Pvalue +### scale_x_FDR, scale_y_FDR, scale_x_logFC, scale_y_logFC, scale_x_Pvalue, scale_y_Pvalue Scales for *x* or *y* aesthetics mapped to *P*-values, FDR (false discovery rate) or log FC (logarithm of fold-change) as used in volcano and quadrant plots of transcriptomics and metabolomics data. diff --git a/vignettes/model-based-annotations.html b/vignettes/model-based-annotations.html index 76e78ad..dbfb463 100644 --- a/vignettes/model-based-annotations.html +++ b/vignettes/model-based-annotations.html @@ -12,7 +12,7 @@ - + Fitted-Model-Based Annotations @@ -339,9 +339,9 @@

Fitted-Model-Based Annotations

-

‘ggpmisc’ 0.5.6.9002

+

‘ggpmisc’ 0.5.6.9003

Pedro J. Aphalo

-

2024-05-24

+

2024-05-27

@@ -1679,8 +1679,8 @@

stat_correlation()

ggplot(my.data, aes(x, y, color = group)) +
   geom_point() +
   stat_correlation(method = "spearman")
-
## Warning in compute_group(...): Skipping bootstrap estimation as 'boot.R' < 50
-## Warning in compute_group(...): Skipping bootstrap estimation as 'boot.R' < 50
+
## Skipping bootstrap estimation as 'conf.level' <= 0
+## Skipping bootstrap estimation as 'conf.level' <= 0

Statistic stat_correlation() generates multiple labels as listed in the tables above. We can combine them freely within a call