YuLab-SMU / aplot

Decorate a plot with associated information
https://yulab-smu.top/aplot
92 stars 14 forks source link

ordering set with scale_*_discret(limits = "") switches back to default ggplot2 ordering when using insert_* #2

Closed darlanminussi closed 4 years ago

darlanminussi commented 4 years ago

Hi, thank you so much for providing aplot.

I believe I have found an issue when trying to set a specific order for two different plots. Here's a reprex to reproduce the issue.

library(aplot)
library(ggplot2)
library(tibble)

set.seed(17)
df <- tibble(id = c("B",
                    "C",
                    "D",
                    "A"),
             sample = c("sp1",
                        "sp2",
                        "sp3",
                        "sp4"),
             value = c(rnorm(1, 1),
                       rnorm(1, 1),
                       rnorm(1, 1),
                       rnorm(1, 1)))

df_anno <- tibble(id = rep("sample", 4),
                  sample = c("sp1",
                             "sp2",
                             "sp3",
                             "sp4"),
                  value = c(rnorm(1, 1),
                            rnorm(1, 1),
                            rnorm(1, 1),
                            rnorm(1, 1)))

p <- ggplot(df) +
  geom_point(aes(x = id,
                 y = sample,
                 size = value)) +
  scale_y_discrete(limits = c("sp3", "sp1", "sp4", "sp2"))

p_anno <- ggplot(df_anno) +
  geom_point(aes(x = id,
                 y = sample,
                 size = value)) +
  scale_y_discrete(limits = c("sp3", "sp1", "sp4", "sp2"))

p %>% 
  insert_left(p_anno)

devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 3.6.2 (2019-12-12)
#>  os       Red Hat Enterprise Linux    
#>  system   x86_64, linux-gnu           
#>  ui       unknown                     
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       America/Chicago             
#>  date     2020-06-26                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date       lib source        
#>  aplot       * 0.0.4   2020-04-07 [1] CRAN (R 3.6.2)
#>  assertthat    0.2.1   2019-03-21 [2] CRAN (R 3.6.0)
#>  backports     1.1.6   2020-04-05 [1] CRAN (R 3.6.2)
#>  callr         3.4.3   2020-03-28 [2] CRAN (R 3.6.2)
#>  cli           2.0.2   2020-02-28 [1] CRAN (R 3.6.2)
#>  colorspace    1.4-1   2019-03-18 [2] CRAN (R 3.6.0)
#>  crayon        1.3.4   2017-09-16 [2] CRAN (R 3.6.0)
#>  desc          1.2.0   2018-05-01 [2] CRAN (R 3.6.0)
#>  devtools      2.3.0   2020-04-10 [1] CRAN (R 3.6.2)
#>  digest        0.6.25  2020-02-23 [2] CRAN (R 3.6.2)
#>  dplyr         0.8.5   2020-03-07 [2] CRAN (R 3.6.2)
#>  ellipsis      0.3.0   2019-09-20 [2] CRAN (R 3.6.0)
#>  evaluate      0.14    2019-05-28 [2] CRAN (R 3.6.0)
#>  fansi         0.4.1   2020-01-08 [1] CRAN (R 3.6.2)
#>  farver        2.0.3   2020-01-16 [1] CRAN (R 3.6.2)
#>  fs            1.4.1   2020-04-04 [1] CRAN (R 3.6.2)
#>  ggplot2     * 3.2.1   2019-08-10 [1] CRAN (R 3.6.2)
#>  glue          1.4.0   2020-04-03 [1] CRAN (R 3.6.2)
#>  gtable        0.3.0   2019-03-25 [2] CRAN (R 3.6.0)
#>  highr         0.8     2019-03-20 [2] CRAN (R 3.6.0)
#>  htmltools     0.4.0   2019-10-04 [2] CRAN (R 3.6.0)
#>  knitr         1.28    2020-02-06 [2] CRAN (R 3.6.2)
#>  labeling      0.3     2014-08-23 [2] CRAN (R 3.6.0)
#>  lazyeval      0.2.2   2019-03-15 [2] CRAN (R 3.6.0)
#>  lifecycle     0.2.0   2020-03-06 [1] CRAN (R 3.6.2)
#>  magrittr      1.5     2014-11-22 [2] CRAN (R 3.6.0)
#>  memoise       1.1.0   2017-04-21 [2] CRAN (R 3.6.0)
#>  munsell       0.5.0   2018-06-12 [2] CRAN (R 3.6.0)
#>  patchwork     1.0.0   2019-12-01 [1] CRAN (R 3.6.2)
#>  pillar        1.4.3   2019-12-20 [2] CRAN (R 3.6.0)
#>  pkgbuild      1.0.6   2019-10-09 [2] CRAN (R 3.6.0)
#>  pkgconfig     2.0.3   2019-09-22 [2] CRAN (R 3.6.0)
#>  pkgload       1.0.2   2018-10-29 [2] CRAN (R 3.6.0)
#>  prettyunits   1.1.1   2020-01-24 [1] CRAN (R 3.6.2)
#>  processx      3.4.2   2020-02-09 [2] CRAN (R 3.6.2)
#>  ps            1.3.2   2020-02-13 [2] CRAN (R 3.6.2)
#>  purrr         0.3.3   2019-10-18 [2] CRAN (R 3.6.0)
#>  R6            2.4.1   2019-11-12 [2] CRAN (R 3.6.0)
#>  Rcpp          1.0.4.6 2020-04-09 [1] CRAN (R 3.6.2)
#>  remotes       2.1.1   2020-02-15 [2] CRAN (R 3.6.2)
#>  rlang         0.4.5   2020-03-01 [1] CRAN (R 3.6.2)
#>  rmarkdown     2.1     2020-01-20 [2] CRAN (R 3.6.2)
#>  rprojroot     1.3-2   2018-01-03 [2] CRAN (R 3.6.0)
#>  scales        1.1.0   2019-11-18 [2] CRAN (R 3.6.0)
#>  sessioninfo   1.1.1   2018-11-05 [2] CRAN (R 3.6.0)
#>  stringi       1.4.6   2020-02-17 [1] CRAN (R 3.6.2)
#>  stringr       1.4.0   2019-02-10 [2] CRAN (R 3.6.0)
#>  testthat      2.3.2   2020-03-02 [2] CRAN (R 3.6.2)
#>  tibble      * 3.0.0   2020-03-30 [2] CRAN (R 3.6.2)
#>  tidyselect    1.0.0   2020-01-27 [2] CRAN (R 3.6.2)
#>  usethis       1.6.0   2020-04-09 [1] CRAN (R 3.6.2)
#>  vctrs         0.2.4   2020-03-10 [2] CRAN (R 3.6.2)
#>  withr         2.1.2   2018-03-15 [2] CRAN (R 3.6.0)
#>  xfun          0.12    2020-01-13 [1] CRAN (R 3.6.2)
#>  yaml          2.2.1   2020-02-01 [2] CRAN (R 3.6.2)