tidyverse / reprex

Render bits of R code for sharing, e.g., on GitHub or StackOverflow.
https://reprex.tidyverse.org
Other
741 stars 80 forks source link

overlapping plots in `reprex` with `ggExtra` plots #305

Closed IndrajeetPatil closed 4 years ago

IndrajeetPatil commented 4 years ago

I am using ggplot2-extension ggExtra (cc @daattali) and noticed this unexpected (?) behavior from reprex.

library(ggplot2)

# default --------------------------------------------
ggplot(mtcars, aes(mpg, wt)) + geom_point()


# modify default -------------------------------------
ggplot(mtcars, aes(mpg, wt)) + geom_point() + geom_smooth()
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'

Created on 2020-01-08 by the reprex package (v0.3.0.9001)

Session info ``` r sessioninfo::session_info() #> - Session info --------------------------------------------------------------- #> setting value #> version R version 3.6.2 (2019-12-12) #> os Windows 10 x64 #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate English_United States.1252 #> ctype English_United States.1252 #> tz Europe/Berlin #> date 2020-01-08 #> #> - Packages ------------------------------------------------------------------- #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0) #> backports 1.1.5 2019-10-02 [1] CRAN (R 3.6.1) #> cli 2.0.0.9000 2019-12-23 [1] Github (r-lib/cli@0293ae7) #> colorspace 1.4-1 2019-03-18 [1] CRAN (R 3.6.0) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.5.1) #> curl 4.3 2019-12-02 [1] CRAN (R 3.6.1) #> digest 0.6.23 2019-11-23 [1] CRAN (R 3.6.1) #> dplyr 0.8.3 2019-07-04 [1] CRAN (R 3.6.2) #> evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.0) #> fansi 0.4.0 2018-11-05 [1] Github (brodieG/fansi@ab11e9c) #> farver 2.0.1 2019-11-13 [1] CRAN (R 3.6.1) #> fastmap 1.0.1 2019-10-08 [1] CRAN (R 3.6.1) #> fs 1.3.1 2019-05-06 [1] CRAN (R 3.6.0) #> ggExtra * 0.9 2019-08-27 [1] CRAN (R 3.6.1) #> ggplot2 * 3.2.1 2019-08-10 [1] CRAN (R 3.6.1) #> glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.0) #> gtable 0.3.0 2019-03-25 [1] CRAN (R 3.6.0) #> highr 0.8 2019-03-20 [1] CRAN (R 3.6.0) #> htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.1) #> httpuv 1.5.2 2019-09-11 [1] CRAN (R 3.6.1) #> httr 1.4.1 2019-08-05 [1] CRAN (R 3.6.1) #> knitr 1.26 2019-11-12 [1] CRAN (R 3.6.1) #> labeling 0.3 2014-08-23 [1] CRAN (R 3.5.0) #> later 1.0.0 2019-10-04 [1] CRAN (R 3.6.1) #> lazyeval 0.2.2 2019-03-15 [1] CRAN (R 3.6.0) #> lifecycle 0.1.0 2019-08-01 [1] CRAN (R 3.6.1) #> magrittr 1.5 2014-11-22 [1] CRAN (R 3.5.1) #> mime 0.8 2019-12-19 [1] CRAN (R 3.6.1) #> miniUI 0.1.1.1 2018-05-18 [1] CRAN (R 3.5.1) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 3.5.1) #> pillar 1.4.3 2019-12-20 [1] CRAN (R 3.6.2) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.1) #> promises 1.1.0 2019-10-04 [1] CRAN (R 3.6.1) #> purrr 0.3.3 2019-10-18 [1] CRAN (R 3.6.1) #> R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.1) #> Rcpp 1.0.3 2019-11-08 [1] CRAN (R 3.6.1) #> reprex 0.3.0.9001 2019-12-30 [1] Github (tidyverse/reprex@27aa69a) #> rlang 0.4.2 2019-11-23 [1] CRAN (R 3.6.2) #> rmarkdown 2.0 2019-12-12 [1] CRAN (R 3.6.1) #> rstudioapi 0.10 2019-03-19 [1] CRAN (R 3.6.0) #> scales 1.1.0 2019-11-18 [1] CRAN (R 3.6.1) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.0) #> shiny 1.4.0 2019-10-10 [1] CRAN (R 3.6.1) #> stringi 1.4.3 2019-03-12 [1] CRAN (R 3.6.0) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.0) #> styler 1.2.0.9000 2020-01-02 [1] Github (r-lib/styler@ca3d2b0) #> tibble 2.1.3 2019-06-06 [1] CRAN (R 3.6.2) #> tidyselect 0.2.5 2018-10-11 [1] CRAN (R 3.6.2) #> withr 2.1.2 2018-03-15 [1] CRAN (R 3.5.1) #> xfun 0.11 2019-11-12 [1] CRAN (R 3.6.1) #> xml2 1.2.2 2019-08-09 [1] CRAN (R 3.6.1) #> xtable 1.8-4 2019-04-21 [1] CRAN (R 3.5.3) #> yaml 2.2.0 2018-07-25 [1] CRAN (R 3.5.1) #> #> [1] C:/Users/inp099/Documents/R/win-library/3.6 #> [2] C:/Program Files/R/R-3.6.2/library ```
library(ggExtra)
library(ggplot2)

# default --------------------------------------------
ggplot(mtcars, aes(mpg, wt)) + geom_point()


# modify default -------------------------------------
ggplot(mtcars, aes(mpg, wt)) + geom_point() + geom_smooth()
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'

# ggExtra --------------------------------------------
ggMarginal(ggplot(mtcars, aes(mpg, wt)) + geom_point())

Created on 2020-01-08 by the reprex package (v0.3.0.9001)

Session info ``` r sessioninfo::session_info() #> - Session info --------------------------------------------------------------- #> setting value #> version R version 3.6.2 (2019-12-12) #> os Windows 10 x64 #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate English_United States.1252 #> ctype English_United States.1252 #> tz Europe/Berlin #> date 2020-01-08 #> #> - Packages ------------------------------------------------------------------- #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0) #> backports 1.1.5 2019-10-02 [1] CRAN (R 3.6.1) #> cli 2.0.0.9000 2019-12-23 [1] Github (r-lib/cli@0293ae7) #> colorspace 1.4-1 2019-03-18 [1] CRAN (R 3.6.0) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.5.1) #> curl 4.3 2019-12-02 [1] CRAN (R 3.6.1) #> digest 0.6.23 2019-11-23 [1] CRAN (R 3.6.1) #> dplyr 0.8.3 2019-07-04 [1] CRAN (R 3.6.2) #> evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.0) #> fansi 0.4.0 2018-11-05 [1] Github (brodieG/fansi@ab11e9c) #> farver 2.0.1 2019-11-13 [1] CRAN (R 3.6.1) #> fastmap 1.0.1 2019-10-08 [1] CRAN (R 3.6.1) #> fs 1.3.1 2019-05-06 [1] CRAN (R 3.6.0) #> ggExtra * 0.9 2019-08-27 [1] CRAN (R 3.6.1) #> ggplot2 * 3.2.1 2019-08-10 [1] CRAN (R 3.6.1) #> glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.0) #> gtable 0.3.0 2019-03-25 [1] CRAN (R 3.6.0) #> highr 0.8 2019-03-20 [1] CRAN (R 3.6.0) #> htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.1) #> httpuv 1.5.2 2019-09-11 [1] CRAN (R 3.6.1) #> httr 1.4.1 2019-08-05 [1] CRAN (R 3.6.1) #> knitr 1.26 2019-11-12 [1] CRAN (R 3.6.1) #> labeling 0.3 2014-08-23 [1] CRAN (R 3.5.0) #> later 1.0.0 2019-10-04 [1] CRAN (R 3.6.1) #> lazyeval 0.2.2 2019-03-15 [1] CRAN (R 3.6.0) #> lifecycle 0.1.0 2019-08-01 [1] CRAN (R 3.6.1) #> magrittr 1.5 2014-11-22 [1] CRAN (R 3.5.1) #> mime 0.8 2019-12-19 [1] CRAN (R 3.6.1) #> miniUI 0.1.1.1 2018-05-18 [1] CRAN (R 3.5.1) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 3.5.1) #> pillar 1.4.3 2019-12-20 [1] CRAN (R 3.6.2) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.1) #> promises 1.1.0 2019-10-04 [1] CRAN (R 3.6.1) #> purrr 0.3.3 2019-10-18 [1] CRAN (R 3.6.1) #> R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.1) #> Rcpp 1.0.3 2019-11-08 [1] CRAN (R 3.6.1) #> reprex 0.3.0.9001 2019-12-30 [1] Github (tidyverse/reprex@27aa69a) #> rlang 0.4.2 2019-11-23 [1] CRAN (R 3.6.2) #> rmarkdown 2.0 2019-12-12 [1] CRAN (R 3.6.1) #> rstudioapi 0.10 2019-03-19 [1] CRAN (R 3.6.0) #> scales 1.1.0 2019-11-18 [1] CRAN (R 3.6.1) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.0) #> shiny 1.4.0 2019-10-10 [1] CRAN (R 3.6.1) #> stringi 1.4.3 2019-03-12 [1] CRAN (R 3.6.0) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.0) #> styler 1.2.0.9000 2020-01-02 [1] Github (r-lib/styler@ca3d2b0) #> tibble 2.1.3 2019-06-06 [1] CRAN (R 3.6.2) #> tidyselect 0.2.5 2018-10-11 [1] CRAN (R 3.6.2) #> withr 2.1.2 2018-03-15 [1] CRAN (R 3.5.1) #> xfun 0.11 2019-11-12 [1] CRAN (R 3.6.1) #> xml2 1.2.2 2019-08-09 [1] CRAN (R 3.6.1) #> xtable 1.8-4 2019-04-21 [1] CRAN (R 3.5.3) #> yaml 2.2.0 2018-07-25 [1] CRAN (R 3.5.1) #> #> [1] C:/Users/inp099/Documents/R/win-library/3.6 #> [2] C:/Program Files/R/R-3.6.2/library ```
jennybc commented 4 years ago

Can you put this code into a regular .R or .Rmd and render it (so cut reprex out of the equation) and see what happens? I'm skeptical that this is ultimately going to be a reprex issue.

daattali commented 4 years ago

I haven't tried your code but I agree with Jenny, it's much more likely this is an issue with ggExtra rather than reprex. If you can reproduce the issue without the use of the "reprex" package, please post the issue on ggExtra

On Wed., Jan. 8, 2020, 18:11 Jennifer (Jenny) Bryan, < notifications@github.com> wrote:

Can you put this code into a regular .R or .Rmd and render it (so cut reprex out of the equation) and see what happens? I'm skeptical that this is ultimately going to be a reprex issue.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tidyverse/reprex/issues/305?email_source=notifications&email_token=AAHIQFCN6KJJGU2PL3PAKT3Q4ZMRPA5CNFSM4KEOGUJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIOKJZQ#issuecomment-572302566, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHIQFAE7OWJZ4FSZUTU7BDQ4ZMRPANCNFSM4KEOGUJQ .

IndrajeetPatil commented 4 years ago

Closing following https://github.com/r-lib/pkgdown/issues/1207#issuecomment-575899270