eulerr icon indicating copy to clipboard operation
eulerr copied to clipboard

Fit multiple euler plots at the same time and maintain proportionality

Open cpsievert opened this issue 5 years ago • 5 comments

This SO response suggests that the following should work to generate multiple euler plots in shared axes.

# devtools::install_github("jolars/eulerr")

library(eulerr)
library(latticeExtra)

p1 <- plot(euler(c(A = 1, B = 8, "A&B" = 1)))
p2 <- plot(euler(c(A = 1, C = 1, "A&C" = 1)))

c(p1, p2, x.same = TRUE, y.same = TRUE)

However, this is the result:

$name
[1] "euler.diagram"

$gp
NULL

$vp
viewport[euler.vp] 

$children
(gTree[canvas.grob]) 

$childrenOrder
   euler_grob 
"canvas.grob" 

$name
[1] "euler.diagram"

$gp
NULL

$vp
viewport[euler.vp] 

$children
(gTree[canvas.grob]) 

$childrenOrder
   euler_grob 
"canvas.grob" 

$x.same
[1] TRUE

$y.same
[1] TRUE
> session_info()
─ Session info ───────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.5.3 (2019-03-11)
 os       macOS Mojave 10.14.3        
 system   x86_64, darwin15.6.0        
 ui       X11                         
 language (EN)                        
 collate  en_US.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       America/Chicago             
 date     2019-03-27                  

─ Packages ───────────────────────────────────────────────────────────────────
 package      * version    date       lib source                               
 assertthat     0.2.1      2019-03-21 [1] CRAN (R 3.5.2)                       
 backports      1.1.3      2018-12-14 [1] CRAN (R 3.5.0)                       
 callr          3.2.0      2019-03-15 [1] CRAN (R 3.5.2)                       
 cli            1.1.0      2019-03-19 [1] CRAN (R 3.5.2)                       
 colorout       1.2-0      2018-09-20 [1] Github (jalvesaq/colorout@cc5fbfa)   
 crayon         1.3.4      2017-09-16 [1] CRAN (R 3.5.0)                       
 desc           1.2.0      2019-03-04 [1] Github (r-lib/desc@ef9e3a4)          
 devtools     * 2.0.1      2018-10-26 [1] CRAN (R 3.5.1)                       
 digest         0.6.18     2018-10-10 [1] CRAN (R 3.5.1)                       
 eulerr       * 5.1.0.9000 2019-03-27 [1] Github (jolars/eulerr@0e14b54)       
 fortunes       1.5-4      2016-12-29 [1] CRAN (R 3.5.0)                       
 fs             1.2.6      2018-08-23 [1] CRAN (R 3.5.0)                       
 glue           1.3.1      2019-03-12 [1] CRAN (R 3.5.2)                       
 htmltools      0.3.6.9003 2019-03-11 [1] local                                
 htmlwidgets    1.3        2019-03-13 [1] Github (ramnathv/htmlwidgets@c998fae)
 lattice      * 0.20-38    2018-11-04 [1] CRAN (R 3.5.3)                       
 latticeExtra * 0.6-28     2016-02-09 [1] CRAN (R 3.5.0)                       
 magrittr       1.5        2014-11-22 [1] CRAN (R 3.5.0)                       
 memoise        1.1.0.9000 2019-02-01 [1] Github (hadley/memoise@1650ad7)      
 pkgbuild       1.0.3      2019-03-20 [1] CRAN (R 3.5.2)                       
 pkgload        1.0.2      2018-10-29 [1] CRAN (R 3.5.1)                       
 polyclip       1.10-0     2019-03-14 [1] CRAN (R 3.5.2)                       
 polylabelr     0.1.0      2018-11-02 [1] CRAN (R 3.5.0)                       
 prettyunits    1.0.2      2015-07-13 [1] CRAN (R 3.5.0)                       
 processx       3.3.0      2019-03-10 [1] CRAN (R 3.5.2)                       
 ps             1.3.0      2018-12-21 [1] CRAN (R 3.5.1)                       
 R6             2.4.0      2019-02-14 [1] CRAN (R 3.5.2)                       
 RColorBrewer * 1.1-2      2014-12-07 [1] CRAN (R 3.5.0)                       
 Rcpp           1.0.1      2019-03-17 [1] CRAN (R 3.5.2)                       
 remotes        2.0.2      2018-10-30 [1] CRAN (R 3.5.1)                       
 rlang          0.3.2      2019-03-21 [1] CRAN (R 3.5.2)                       
 rprojroot      1.3-2      2018-01-03 [1] CRAN (R 3.5.0)                       
 sessioninfo    1.1.1      2018-11-05 [1] CRAN (R 3.5.0)                       
 testthat       2.0.1      2018-10-13 [1] CRAN (R 3.5.0)                       
 usethis      * 1.4.0.9000 2018-10-05 [1] Github (r-lib/usethis@1e3c6a6)       
 withr          2.1.2      2018-03-15 [1] CRAN (R 3.5.0)                       

[1] /Library/Frameworks/R.framework/Versions/3.5/Resources/library

cpsievert avatar Mar 27 '19 23:03 cpsievert

Thanks for noticing this! I have edited my answer there so that it should work properly now. Since the package no longer uses lattice, the c.trellis() method won't work any more and you have to use gridExtra instead (or grid itself). Here is a working example:

library(eulerr)

p1 <- plot(euler(c(A = 1, B = 8, "A&B" = 1)))
p2 <- plot(euler(c(A = 1, C = 1, "A&C" = 1)))

gridExtra::grid.arrange(p1, p2)

image

jolars avatar Mar 28 '19 07:03 jolars

Is there anyway to combine them such that the area of A stays constant across the plots?

cpsievert avatar Mar 28 '19 14:03 cpsievert

No good way at the moment I'm afraid. But it shouldn't be hard to implement, as the following silly hack proves:

m <- matrix(c(T, F, F, 
            rep(c(F, T, F), 8),
            c(T, T, F),
            c(T, F, T),
            c(T, F, F),
            c(F, F, T)), nrow = 3)

d <- as.data.frame(t(m))
colnames(d) <- LETTERS[1:3]
d$f <- c(rep("X", 10), rep("Y", 3))

g <- eulerr::euler(d, by = f)
plot(g)

image

jolars avatar Mar 28 '19 15:03 jolars

Is it possible to control the positions of the multiple plots? As in, if I have 4 plots to have the ability to have a 2x2 grid instead of a 1x4 (how it is currently handled).

hummuscience avatar Jan 28 '21 20:01 hummuscience

@Cumol, unfortunately not at the moment. But I agree that this would be a useful option.

jolars avatar Feb 08 '21 11:02 jolars