diff --git a/DESCRIPTION b/DESCRIPTION index 4ad9aba..c6c4997 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,7 +18,8 @@ Imports: magrittr, methods, utils, - yulab.utils (>= 0.1.9) + yulab.utils (>= 0.1.9), + pillar Suggests: ggtree URL: https://github.com/YuLab-SMU/aplot, https://yulab-smu.top/aplot/ diff --git a/NAMESPACE b/NAMESPACE index a750dee..f515726 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -45,6 +45,7 @@ importFrom(ggplot2,element_text) importFrom(ggplot2,ggplot) importFrom(ggplot2,ggplotGrob) importFrom(ggplot2,ggplot_add) +importFrom(ggplot2,ggplot_build) importFrom(ggplot2,ggsave) importFrom(ggplot2,is.ggplot) importFrom(ggplot2,labs) @@ -66,4 +67,5 @@ importFrom(patchwork,patchworkGrob) importFrom(patchwork,plot_annotation) importFrom(patchwork,plot_layout) importFrom(patchwork,plot_spacer) -importFrom(utils,modifyList) +importFrom(pillar,style_subtle) +importFrom(utils,packageDescription) diff --git a/R/plot-list.R b/R/plot-list.R index 5a6a543..e2a71a1 100644 --- a/R/plot-list.R +++ b/R/plot-list.R @@ -22,7 +22,6 @@ ##' @importFrom ggplot2 theme ##' @importFrom ggplot2 element_text ##' @importFrom ggplot2 labs -##' @importFrom utils modifyList ##' @importFrom ggfun ggbreak2ggplot ##' @export ##' @author Guangchuang Yu @@ -93,7 +92,7 @@ plot_list <- function(..., gglist = NULL, - +#' @importFrom ggplot2 ggplot_build plot_list2 <- function(gglist = NULL, ncol = NULL, nrow = NULL, @@ -117,11 +116,11 @@ plot_list2 <- function(gglist = NULL, ) if (!is.null(tag_levels) || !is.null(labels)) { - pt <- p$theme$plot.tag + pt <- ggplot_build(p)$plot$theme$plot.tag if (is.null(pt)){ pt <- ggplot2::element_text() } - pt <- modifyList(pt, list(size = tag_size)) + pt$size <- tag_size p <- p + plot_annotation(tag_levels=tag_levels) & theme(plot.tag = pt) } diff --git a/R/zzz.R b/R/zzz.R new file mode 100644 index 0000000..cf1cac5 --- /dev/null +++ b/R/zzz.R @@ -0,0 +1,30 @@ +#' @importFrom utils packageDescription +#' @importFrom pillar style_subtle +.onAttach <- function(libname, pkgname) { + pkgVersion <- packageDescription(pkgname, fields="Version") + msg <- paste0(pkgname, " v", pkgVersion, " ", + "For help: https://github.com/YuLab-SMU/aplot/issues", "\n\n") + + citation <- paste0("If you use ", pkgname, + " in published research, please cite the paper:\n\n", + aplot_citations()) + + packageStartupMessage(paste0(strwrap(pillar::style_subtle(paste0(msg, citation, suppressmsg(pkgname)))), collapse="\n")) +} + +aplot_citations <- function(){ + paste("Shuangbin Xu, Qianwen Wang, Shaodi Wen, Junrui Li, Nan He, Ming Li, Thomas Hackl, Rui Wang, + Dongqiang Zeng, Shixiang Wang, Shensuo Li, Chunhui Gao, Lang Zhou, Shaoguo Tao, Zijing Xie, + Lin Deng, and Guangchuang Yu.", + "aplot: Simplifying the creation of complex graphs to visualize associations across diverse data types.", + "The Innovation. 2025, 6(9):100958. doi: 10.1016/j.xinn.2025.100958\n\n", + "Export the citation to BibTex by citation('aplot')\n\n" + ) + +} + +suppressmsg <- function(pkgname){ + paste0("This message can be suppressed by:\n", + "suppressPackageStartupMessages(library(", pkgname ,"))" + ) +}