ggpubr icon indicating copy to clipboard operation
ggpubr copied to clipboard

Error R2 with stat_cor function

Open liuxiawei opened this issue 10 months ago • 0 comments

I tried to use the stat_cor, stat_regline_equation and stat_smooth function to perform statistics on a scatter plot, and I wanted to try both the y~log(x,base=2) and y~x formula simultaneously. However, the final results showed that the R2 and P values obtained from both functions were same. Even when I commented out one group of the stat_smooth, stat_cor, and stat_regline_equation functions, the results remained the same. Is this right or Bug?


Expected behavior

Draw stat_cor with formula y= log(x,base=2) and y=x in same plot , Show different R2 value

Actual behavior

Draw stat_cor with formula y~log(x,base=2) and y~x in same plot , Show same R2 value 图片 图片

Steps to reproduce the problem

Draw stat_cor with formula y~ log(x,base=2) and y~x in same plot

draw_mean_pic<-function(tmp_data){
   ssp_data_means<- ggscatter(tmp_data,x="Original",y="Normalized")+
# try draw with formula =y~x
  stat_smooth(method='lm', se=FALSE, color='turquoise4' ,formula =y~x) +
    stat_cor(aes( label =paste(..rr.label.., ..p.label.., sep = "~`,`~")),check_overlap = TRUE,label.y.npc=0.9,label.x.npc=0.02)  +
    stat_regline_equation(  check_overlap = TRUE,label.y.npc=0.98,label.x.npc=0.02 ,formula =y~x)+

  xlab("Original Mean") +
  ylab("Normalized Mean") +

    stat_smooth(method = "lm",  se=T,formula =y ~ log(x,base = 2) )+
  stat_cor(aes( label =paste(..rr.label.., ..p.label.., sep = "~`,`~")),check_overlap = TRUE,label.y.npc=0.76,label.x.npc=0.02)+
  stat_regline_equation(
    check_overlap = TRUE,
    aes(label  = sub("x", "log2(x)", ..eq.label..)),
    formula = y ~ log(x,base = 2),
    label.y.npc=0.84,label.x.npc=0.02
  )+

  ggtitle("Comparison of Mean  before and after Normalization") 
ssp_data_means

}
draw_mean_pic(data)

session_info()

 setting  value
 version  R version 4.3.1 (2023-06-16)
 os       UnionTech OS Desktop 20 Home
 system   x86_64, linux-gnu
 ui       RStudio
 language zh_CN
 collate  C.UTF-8
 ctype    C.UTF-8
 tz       Asia/Beijing
 date     2024-03-29
 rstudio  1.1.456 (desktop)
 pandoc   2.12 @ /home/liuxiawei/micromamba/envs/r/bin/ (via rmarkdown)

─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package              * version    date (UTC) lib source
 abind                  1.4-5      2016-07-21 [1] CRAN (R 4.3.1)
 ape                    5.7-1      2023-03-13 [1] CRAN (R 4.3.1)
 backports              1.4.1      2021-12-13 [1] CRAN (R 4.3.1)
 beeswarm               0.4.0      2021-06-01 [1] CRAN (R 4.3.1)
 biglm                  0.9-2.1    2020-11-27 [1] CRAN (R 4.3.1)
 Biobase                2.62.0     2023-10-24 [1] Bioconductor
 BiocGenerics         * 0.48.1     2023-11-01 [1] Bioconductor
 BiocParallel         * 1.36.0     2023-10-24 [1] Bioconductor
 bit                    4.0.5      2022-11-15 [1] CRAN (R 4.3.1)
 bit64                  4.0.5      2020-08-30 [1] CRAN (R 4.3.1)
 bitops                 1.0-7      2021-04-24 [1] CRAN (R 4.3.1)
 broom                  1.0.5      2023-06-09 [1] CRAN (R 4.3.1)
 bslib                  0.6.1      2023-11-28 [1] CRAN (R 4.3.1)
 cachem                 1.0.8      2023-05-01 [1] CRAN (R 4.3.1)
 car                    3.1-2      2023-03-30 [1] CRAN (R 4.3.1)
 carData                3.0-5      2022-01-06 [1] CRAN (R 4.3.1)
 Cardinal             3.4.3      2023-11-23 [1] Bioconductor 3.18 (R 4.3.1)
 CardinalIO             1.0.0      2023-10-24 [1] Bioconductor
 cli                    3.6.2      2023-12-11 [1] CRAN (R 4.3.2)
 cluster                2.1.6      2023-12-01 [1] CRAN (R 4.3.1)
 codetools              0.2-19     2023-02-01 [1] CRAN (R 4.3.1)
 colorspace             2.1-0      2023-01-23 [1] CRAN (R 4.3.1)
 confintr               1.0.2      2023-06-04 [1] CRAN (R 4.3.1)
 cowplot                1.1.3      2024-01-22 [1] CRAN (R 4.3.1)
 crayon                 1.5.2      2022-09-29 [1] CRAN (R 4.3.1)
 data.table             1.15.2     2024-02-29 [1] CRAN (R 4.3.1)
 DBI                    1.2.2      2024-02-16 [1] CRAN (R 4.3.2)
 DelayedArray           0.28.0     2023-10-24 [1] Bioconductor
 DelayedMatrixStats     1.24.0     2023-10-24 [1] Bioconductor
 deldir                 2.0-4      2024-02-28 [1] CRAN (R 4.3.1)
 devtools               2.4.5      2022-10-11 [1] CRAN (R 4.3.1)
 digest                 0.6.35     2024-03-11 [1] CRAN (R 4.3.1)
 dotCall64              1.1-1      2023-11-28 [1] CRAN (R 4.3.1)
 dplyr                * 1.1.4      2023-11-17 [1] CRAN (R 4.3.2)
 EBImage              * 4.44.0     2023-10-24 [1] Bioconductor
 ellipsis               0.3.2      2021-04-29 [1] CRAN (R 4.3.1)
 evaluate               0.23       2023-11-01 [1] CRAN (R 4.3.1)
 fansi                  1.0.6      2023-12-08 [1] CRAN (R 4.3.1)
 farver                 2.1.1      2022-07-06 [1] CRAN (R 4.3.1)
 fastDummies            1.7.3      2023-07-06 [1] CRAN (R 4.3.1)
 fastmap                1.1.1      2023-02-24 [1] CRAN (R 4.3.1)
 fftwtools              0.9-11     2021-03-01 [1] CRAN (R 4.3.1)
 fitdistrplus           1.1-11     2023-04-25 [1] CRAN (R 4.3.1)
 fs                     1.6.3      2023-07-20 [1] CRAN (R 4.3.1)
 future                 1.33.1     2023-12-22 [1] CRAN (R 4.3.2)
 future.apply           1.11.1     2023-12-21 [1] CRAN (R 4.3.2)
 generics               0.1.3      2022-07-05 [1] CRAN (R 4.3.1)
 GenomeInfoDb           1.38.8     2024-03-15 [1] Bioconductor 3.18 (R 4.3.1)
 GenomeInfoDbData       1.2.11     2024-03-20 [1] Bioconductor
 GenomicRanges          1.54.1     2023-10-29 [1] Bioconductor
 ggbeeswarm             0.7.2      2023-04-29 [1] CRAN (R 4.3.1)
 ggplot2              * 3.5.0      2024-02-23 [1] CRAN (R 4.3.1)
 ggpmisc              * 0.5.5      2023-11-15 [1] CRAN (R 4.3.1)
 ggpp                 * 0.5.6      2024-01-09 [1] CRAN (R 4.3.1)
 ggpubr               * 0.6.0      2023-02-10 [1] CRAN (R 4.3.1)
 ggrastr                1.0.2      2023-06-01 [1] CRAN (R 4.3.1)
 ggrepel                0.9.5      2024-01-10 [1] CRAN (R 4.3.1)
 ggridges               0.5.6      2024-01-23 [1] CRAN (R 4.3.1)
 ggsignif               0.6.4      2022-10-13 [1] CRAN (R 4.3.1)
 glmGamPoi              1.14.3     2024-02-11 [1] Bioconductor 3.18 (R 4.3.1)
 globals                0.16.3     2024-03-08 [1] CRAN (R 4.3.3)
 glue                   1.7.0      2024-01-09 [1] CRAN (R 4.3.1)
 goftest                1.2-3      2021-10-07 [1] CRAN (R 4.3.1)
 gridExtra              2.3        2017-09-09 [1] CRAN (R 4.3.1)
 gtable                 0.3.4      2023-08-21 [1] CRAN (R 4.3.1)
 hdf5r                  1.3.10     2024-03-02 [1] CRAN (R 4.3.1)
 htmltools              0.5.7      2023-11-03 [1] CRAN (R 4.3.1)
 htmlwidgets            1.6.4      2023-12-06 [1] CRAN (R 4.3.1)
 httpuv                 1.6.14     2024-01-26 [1] CRAN (R 4.3.1)
 httr                   1.4.7      2023-08-15 [1] CRAN (R 4.3.1)
 ica                    1.0-3      2022-07-08 [1] CRAN (R 4.3.1)
 igraph                 2.0.3      2024-03-13 [1] CRAN (R 4.3.1)
 IRanges                2.36.0     2023-10-24 [1] Bioconductor
 irlba                  2.3.5.1    2022-10-03 [1] CRAN (R 4.3.1)
 jpeg                   0.1-10     2022-11-29 [1] CRAN (R 4.3.1)
 jquerylib              0.1.4      2021-04-26 [1] CRAN (R 4.3.1)
 jsonlite               1.8.8      2023-12-04 [1] CRAN (R 4.3.1)
 KernSmooth             2.23-22    2023-07-10 [1] CRAN (R 4.3.1)
 knitr                  1.45       2023-10-30 [1] CRAN (R 4.3.1)
 labeling               0.4.3      2023-08-29 [1] CRAN (R 4.3.1)
 later                  1.3.2      2023-12-06 [1] CRAN (R 4.3.1)
 lattice                0.22-6     2024-03-20 [1] CRAN (R 4.3.1)
 lazyeval               0.2.2      2019-03-15 [1] CRAN (R 4.3.1)
 leiden                 0.4.3.1    2023-11-17 [1] CRAN (R 4.3.1)
 lifecycle              1.0.4      2023-11-07 [1] CRAN (R 4.3.2)
 listenv                0.9.1      2024-01-29 [1] CRAN (R 4.3.1)
 lmodel2                1.7-3      2018-02-05 [1] CRAN (R 4.3.1)
 lmtest                 0.9-40     2022-03-21 [1] CRAN (R 4.3.1)
 locfit                 1.5-9.9    2024-03-01 [1] CRAN (R 4.3.1)
 magrittr               2.0.3      2022-03-30 [1] CRAN (R 4.3.1)
 MASS                   7.3-60.0.1 2024-01-13 [1] CRAN (R 4.3.1)
 Matrix                 1.6-5      2024-01-11 [1] CRAN (R 4.3.1)
 MatrixGenerics         1.14.0     2023-10-24 [1] Bioconductor
 MatrixModels           0.5-3      2023-11-06 [1] CRAN (R 4.3.1)
 matrixStats            1.2.0      2023-12-11 [1] CRAN (R 4.3.1)
 matter                 2.4.1      2024-03-13 [1] Bioconductor 3.18 (R 4.3.1)
 mclust                 6.1        2024-02-23 [1] CRAN (R 4.3.1)
 memoise                2.0.1      2021-11-26 [1] CRAN (R 4.3.1)
 mgcv                   1.9-1      2023-12-21 [1] CRAN (R 4.3.1)
 mime                   0.12       2021-09-28 [1] CRAN (R 4.3.1)
 miniUI                 0.1.1.1    2018-05-18 [1] CRAN (R 4.3.1)
 munsell                0.5.0      2018-06-12 [1] CRAN (R 4.3.1)
 nlme                   3.1-164    2023-11-27 [1] CRAN (R 4.3.1)
 ontologyIndex          2.12       2024-02-27 [1] CRAN (R 4.3.1)
 parallelly             1.37.1     2024-02-29 [1] CRAN (R 4.3.1)
 patchwork            * 1.2.0      2024-01-08 [1] CRAN (R 4.3.1)
 pbapply                1.7-2      2023-06-27 [1] CRAN (R 4.3.1)
 pillar                 1.9.0      2023-03-22 [1] CRAN (R 4.3.1)
 pkgbuild               1.4.4      2024-03-17 [1] CRAN (R 4.3.1)
 pkgconfig              2.0.3      2019-09-22 [1] CRAN (R 4.3.1)
 pkgload                1.3.4      2024-01-16 [1] CRAN (R 4.3.1)
 plotly                 4.10.4     2024-01-13 [1] CRAN (R 4.3.1)
 plyr                   1.8.9      2023-10-02 [1] CRAN (R 4.3.1)
 png                    0.1-8      2022-11-29 [1] CRAN (R 4.3.1)
 polyclip               1.10-6     2023-09-27 [1] CRAN (R 4.3.1)
 polynom                1.4-1      2022-04-11 [1] CRAN (R 4.3.1)
 profvis                0.3.8      2023-05-02 [1] CRAN (R 4.3.1)
 progressr              0.14.0     2023-08-10 [1] CRAN (R 4.3.1)
 promises               1.2.1      2023-08-10 [1] CRAN (R 4.3.1)
 ProtGenerics         * 1.34.0     2023-10-24 [1] Bioconductor
 purrr                  1.0.2      2023-08-10 [1] CRAN (R 4.3.1)
 quantreg               5.97       2023-08-19 [1] CRAN (R 4.3.1)
 R6                     2.5.1      2021-08-19 [1] CRAN (R 4.3.1)
 RANN                   2.6.1      2019-01-08 [1] CRAN (R 4.3.1)
 RColorBrewer           1.1-3      2022-04-03 [1] CRAN (R 4.3.1)
 Rcpp                   1.0.12     2024-01-09 [1] CRAN (R 4.3.1)
 RcppAnnoy              0.0.22     2024-01-23 [1] CRAN (R 4.3.1)
 RcppHNSW               0.6.0      2024-02-04 [1] CRAN (R 4.3.1)
 RCurl                  1.98-1.14  2024-01-09 [1] CRAN (R 4.3.1)
 remotes                2.5.0      2024-03-17 [1] CRAN (R 4.3.1)
 reshape2               1.4.4      2020-04-09 [1] CRAN (R 4.3.1)
 reticulate             1.35.0     2024-01-31 [1] CRAN (R 4.3.1)
 rlang                  1.1.3      2024-01-10 [1] CRAN (R 4.3.1)
 rmarkdown              2.26       2024-03-05 [1] CRAN (R 4.3.1)
 ROCR                   1.0-11     2020-05-02 [1] CRAN (R 4.3.1)
 RSpectra               0.16-1     2022-04-24 [1] CRAN (R 4.3.1)
 rstatix                0.7.2      2023-02-01 [1] CRAN (R 4.3.1)
 rstudioapi             0.15.0     2023-07-07 [1] CRAN (R 4.3.1)
 Rtsne                  0.17       2023-12-07 [1] CRAN (R 4.3.1)
 S4Arrays               1.2.1      2024-03-04 [1] Bioconductor 3.18 (R 4.3.1)
 S4Vectors            * 0.40.2     2023-11-23 [1] Bioconductor 3.18 (R 4.3.2)
 sass                   0.4.9      2024-03-15 [1] CRAN (R 4.3.1)
 scales               * 1.3.0      2023-11-28 [1] CRAN (R 4.3.1)
 scattermore            1.2        2023-06-12 [1] CRAN (R 4.3.1)
 sctransform            0.4.1      2023-10-19 [1] CRAN (R 4.3.1)
 sessioninfo            1.2.2      2021-12-06 [1] CRAN (R 4.3.1)
 Seurat               * 5.0.3      2024-03-18 [1] CRAN (R 4.3.1)
 SeuratDisk           * 0.0.0.9021 2024-03-18 [1] Github (mojaveazure/seurat-disk@877d4e1)
 SeuratObject         * 5.0.1      2023-11-17 [1] CRAN (R 4.3.2)
 shiny                  1.8.0      2023-11-17 [1] CRAN (R 4.3.1)
 signal                 1.8-0      2023-11-27 [1] CRAN (R 4.3.1)
 sp                   * 2.1-3      2024-01-30 [1] CRAN (R 4.3.2)
 spam                   2.10-0     2023-10-23 [1] CRAN (R 4.3.1)
 SparseArray            1.2.4      2024-02-11 [1] Bioconductor 3.18 (R 4.3.1)
 SparseM                1.81       2021-02-18 [1] CRAN (R 4.3.1)
 sparseMatrixStats      1.14.0     2023-10-24 [1] Bioconductor
 spatstat.data          3.0-4      2024-01-15 [1] CRAN (R 4.3.2)
 spatstat.explore       3.2-6      2024-02-01 [1] CRAN (R 4.3.2)
 spatstat.geom          3.2-9      2024-02-28 [1] CRAN (R 4.3.2)
 spatstat.random        3.2-3      2024-02-29 [1] CRAN (R 4.3.3)
 spatstat.sparse        3.0-3      2023-10-24 [1] CRAN (R 4.3.1)
 spatstat.utils         3.0-4      2023-10-24 [1] CRAN (R 4.3.1)
 stringi                1.8.3      2023-12-11 [1] CRAN (R 4.3.1)
 stringr                1.5.1      2023-11-14 [1] CRAN (R 4.3.2)
 SummarizedExperiment   1.32.0     2023-10-24 [1] Bioconductor
 survival               3.5-8      2024-02-14 [1] CRAN (R 4.3.1)
 tensor                 1.5        2012-05-05 [1] CRAN (R 4.3.1)
 tibble                 3.2.1      2023-03-20 [1] CRAN (R 4.3.1)
 tidyr                  1.3.1      2024-01-24 [1] CRAN (R 4.3.2)
 tidyselect             1.2.1      2024-03-11 [1] CRAN (R 4.3.1)
 tiff                   0.1-12     2023-11-28 [1] CRAN (R 4.3.1)
 urlchecker             1.0.1      2021-11-30 [1] CRAN (R 4.3.1)
 usethis                2.2.3      2024-02-19 [1] CRAN (R 4.3.1)
 utf8                   1.2.4      2023-10-22 [1] CRAN (R 4.3.1)
 uwot                   0.1.16     2023-06-29 [1] CRAN (R 4.3.1)
 vctrs                  0.6.5      2023-12-01 [1] CRAN (R 4.3.2)
 vipor                  0.4.7      2023-12-18 [1] CRAN (R 4.3.1)
 viridisLite            0.4.2      2023-05-02 [1] CRAN (R 4.3.1)
 withr                  3.0.0      2024-01-16 [1] CRAN (R 4.3.1)
 xfun                   0.42       2024-02-08 [1] CRAN (R 4.3.1)
 xtable                 1.8-4      2019-04-21 [1] CRAN (R 4.3.1)
 XVector                0.42.0     2023-10-24 [1] Bioconductor
 yaml                   2.3.8      2023-12-11 [1] CRAN (R 4.3.1)
 zlibbioc               1.48.2     2024-03-13 [1] Bioconductor 3.18 (R 4.3.1)
 zoo                    1.8-12     2023-04-13 [1] CRAN (R 4.3.1)

liuxiawei avatar Mar 29 '24 04:03 liuxiawei