ProjectMOSAIC / ggformula

Provides a formula interface to 'ggplot2' graphics.
Other
39 stars 11 forks source link

mapping warning #128

Closed nicholasjhorton closed 2 years ago

nicholasjhorton commented 5 years ago

I got the following warning Warning message: In (function (mapping = NULL, data = NULL, ..., slope, intercept, : Using intercept and/or slope with mapping may not have the desired result as mapping is overwritten if either of these is specified

suppressPackageStartupMessages(library(mosaic))
suppressPackageStartupMessages(library(tidyverse))
ds <- dplyr::tibble(x = rnorm(100), y = rnorm(100))
gf_point(y ~ x, data = ds) %>%
  gf_abline(intercept = 0, slope = 1)
#> Warning in (function (mapping = NULL, data = NULL, ..., slope, intercept, : Using `intercept` and/or `slope` with `mapping` may not have the desired result as mapping is overwritten if either of these is specified

Created on 2019-07-18 by the reprex package (v0.3.0)

sessionInfo() R version 3.6.0 (2019-04-26) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS Mojave 10.14.5

Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] xtable_1.8-4 broom_0.5.2 readxl_1.3.1
[4] data.table_1.12.2 mosaic_1.5.0.9001 Matrix_1.2-17
[7] mosaicData_0.17.0 ggformula_0.9.1.9001 ggstance_0.3.2
[10] ggplot2_3.2.0 lattice_0.20-38 dplyr_0.8.1

loaded via a namespace (and not attached): [1] ggrepel_0.8.1 Rcpp_1.0.1 tidyr_0.8.3 assertthat_0.2.1 [5] zeallot_0.1.0 digest_0.6.19 utf8_1.1.4 mime_0.7
[9] R6_2.4.0 cellranger_1.1.0 backports_1.1.4 evaluate_0.14
[13] pillar_1.4.1 rlang_0.3.4 lazyeval_0.2.2 rstudioapi_0.10 [17] rmarkdown_1.13 labeling_0.3 splines_3.6.0 readr_1.3.1
[21] stringr_1.4.0 htmlwidgets_1.3 munsell_0.5.0 shiny_1.3.2
[25] compiler_3.6.0 httpuv_1.5.1 janitor_1.2.0 xfun_0.8
[29] pkgconfig_2.0.2 htmltools_0.3.6 tidyselect_0.2.5 tibble_2.1.3
[33] gridExtra_2.3 mosaicCore_0.6.0 fansi_0.4.0 crayon_1.3.4
[37] withr_2.1.2 later_0.8.0 MASS_7.3-51.4 grid_3.6.0
[41] nlme_3.1-140 gtable_0.3.0 magrittr_1.5 scales_1.0.0
[45] cli_1.1.0 stringi_1.4.3 promises_1.0.1 leaflet_2.0.2
[49] snakecase_0.11.0 ggdendro_0.1-20 generics_0.0.2 vctrs_0.1.0
[53] tools_3.6.0 glue_1.3.1.9000 purrr_0.3.2 hms_0.4.2
[57] crosstalk_1.0.0 yaml_2.2.0 colorspace_1.4-1 knitr_1.23

rpruim commented 5 years ago

From the NEWS of the dev version of ggplot2:

geom_abline(), geom_hline(), and geom_vline() now issue more informative warnings when supplied with set aesthetics (i.e., slope, intercept, yintercept, and/or xintercept) and mapped aesthetics (i.e., data and/or mapping).

But you can avoid the message if you use mapping rather than setting.

suppressPackageStartupMessages(library(ggformula))
suppressPackageStartupMessages(library(dplyr))
theme_set(theme_bw())
ds <- dplyr::tibble(x = rnorm(100), y = rnorm(100))

# use mapping rather than setting to avoid warning
gf_point(y ~ x, data = ds) %>%
  gf_abline(intercept = ~ 0, slope = ~ 1, alpha = 0.2)

Created on 2019-07-23 by the reprex package (v0.3.0)

I'll have to see if there is a way to rewrite gf_abline() that allows for setting and avoids he warning.

rpruim commented 2 years ago

I think I have a way to handle this: When mapping is empty, I can remove mapping and data from the call. Testing this idea out now:

suppressPackageStartupMessages(library(mosaic))
suppressPackageStartupMessages(library(tidyverse))
ds <- dplyr::tibble(x = rnorm(100), y = rnorm(100))
gf_point(y ~ x, data = ds) %>%
  gf_abline(intercept = 0, slope = 1)

Created on 2022-03-03 by the reprex package (v2.0.1)