YuLab-SMU / aplot

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

Coordinate alignment is not perfect. #32

Closed xiayh17 closed 9 months ago

xiayh17 commented 11 months ago
library(aplot)
library(ggplot2)

set.seed(123)
data1 <- rnorm(1000, mean = -1, sd = 1)
data2 <- rnorm(1000, mean = -2, sd = 2)
data3 <- rnorm(1000, mean = -3, sd = 3)

df1 <- data.frame(
  values = data1,
  group = factor(rep(1, each = 1000))
)

df2 <- data.frame(
  values = data2,
  group = factor(rep(2, each = 1000))
)

df3 <- data.frame(
  values = data3,
  group = factor(rep(3, each = 1000))
)

p1 <- ggplot(df1, aes(x = values, fill = group)) +
  geom_density(alpha = 0.5) +
  labs(title = "P1", x = "value", y = "density", fill = "group") +
  theme_minimal()

p2 <- ggplot(df2, aes(x = values, fill = group)) +
  geom_density(alpha = 0.5) +
  labs(title = "P2", x = "value", y = "density", fill = "group") +
  theme_minimal()

p3 <- ggplot(df3, aes(x = values, fill = group)) +
  geom_density(alpha = 0.5) +
  labs(title = "P3", x = "value", y = "density", fill = "group") +
  theme_minimal()

p1 %>% insert_bottom(p2) %>% insert_bottom(p3)
image
> sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.4.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/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] ggplot2_3.4.1 aplot_0.1.10 

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.10          pillar_1.8.1         compiler_4.2.1       cytolib_2.10.0       yulab.utils_0.0.6    tools_4.2.1         
 [7] zlibbioc_1.44.0      lifecycle_1.0.3      tibble_3.2.0         gtable_0.3.1         pkgconfig_2.0.3      rlang_1.1.1         
[13] graph_1.76.0         ggplotify_0.1.0      cli_3.6.1            DBI_1.1.3            rstudioapi_0.14      Rgraphviz_2.42.0    
[19] patchwork_1.1.2      withr_2.5.0          dplyr_1.1.1          gridGraphics_0.5-1   generics_0.1.3       S4Vectors_0.36.1    
[25] vctrs_0.6.3          stats4_4.2.1         grid_4.2.1           tidyselect_1.2.0     glue_1.6.2           data.table_1.14.8   
[31] Biobase_2.58.0       R6_2.5.1             fansi_1.0.4          XML_3.99-0.13        farver_2.1.1         RProtoBufLib_2.10.0 
[37] magrittr_2.0.3       scales_1.2.1         matrixStats_0.63.0   BiocGenerics_0.44.0  flowWorkspace_4.10.1 flowCore_2.10.0     
[43] colorspace_2.1-0     labeling_0.4.2       ncdfFlow_2.44.0      utf8_1.2.3           munsell_0.5.0        ggfun_0.0.9
GuangchuangYu commented 9 months ago

image

fixed by https://github.com/YuLab-SMU/aplot/pull/36.