Skip to content

Commit

Permalink
Merge branch 'develop-0.5.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
aphalo committed Jun 1, 2024
2 parents fc0f2a1 + f112f8f commit 5facc70
Show file tree
Hide file tree
Showing 15 changed files with 418 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-3385-972X")),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions R/stat-correlation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")],
Expand All @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion R/stat-ma-eq.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion R/stat-multcomp.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion R/stat-poly-eq.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 21 additions & 2 deletions inst-not/GLM/GLM-in-stat-poly_line.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
13 changes: 13 additions & 0 deletions inst-not/quantreg/ggplo2-quantreg-rqss.R
Original file line number Diff line number Diff line change
@@ -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()

25 changes: 25 additions & 0 deletions inst-not/quantreg/ggpmisc-quantreg-rqss.R
Original file line number Diff line number Diff line change
@@ -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()
29 changes: 29 additions & 0 deletions inst-not/quantreg/quantreg-rqss-examples.R
Original file line number Diff line number Diff line change
@@ -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()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 5facc70

Please sign in to comment.