From 5c90538fb87d41db5ab76927f16e628cbc2e3677 Mon Sep 17 00:00:00 2001 From: Qile0317 Date: Wed, 20 Mar 2024 23:08:50 -0700 Subject: [PATCH] updated overlayLegend stuff --- R/insert_legend.R | 17 +++++++++++------ R/typecheck.R | 9 ++++----- man/overlayLegend.Rd | 14 +++++++++++--- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/R/insert_legend.R b/R/insert_legend.R index 70234cb..84ba7d6 100644 --- a/R/insert_legend.R +++ b/R/insert_legend.R @@ -34,9 +34,6 @@ removeLegend <- function(apotc_ggplot) { remove_ggplot_layers(apotc_ggplot, get_legend_layer_indicies(apotc_ggplot)) } -# FIXME -# https://qile0317.github.io/APackOfTheClones/dev/reference/overlayLegend.html - #' @title overlay a clone size legend on an APackOfTheClones plot #' #' @description @@ -54,6 +51,15 @@ removeLegend <- function(apotc_ggplot) { #' [vizAPOTC] #' @inheritParams APOTCPlot #' +#' @details +#' The size legend on APackOfTheClones plots are simply a collection of +#' annotation layers of the `rect`, `text`, `circle` geoms. Therefore it +#' isn't quite a ggplot legend. In the actual ggplot object, the `$layers` +#' element should all be named with an empty character `""`, and those +#' that comprise the annotation layers of the legend should be named whatever +#' `APackOfTheClones:::.ApotcLegendLayerName` is. Note that this is simply +#' an implementation detail that the user should not interfere with. +#' #' @inherit APOTCPlot return #' @export #' @@ -66,9 +72,8 @@ removeLegend <- function(apotc_ggplot) { #' # reposition the legend to top right #' overlayLegend(apotc_plot, legend_position = "top right") #' -#' # use different sizes and label -#' overlayLegend( -#' apotc_plot, +#' # use different sizes and label - may be nice to use the pipe +#' apotc_plot |> overlayLegend( #' legend_sizes = c(1, 3, 7, 9), #' legend_label = "odd sizes" #' ) diff --git a/R/typecheck.R b/R/typecheck.R index 1223923..967abea 100644 --- a/R/typecheck.R +++ b/R/typecheck.R @@ -119,11 +119,10 @@ create_err_msg <- function(typechecker_str_vec) { } get_error_strings <- function(funcstrs) { - funcstrs %>% - sapply( - function(s) prepend_indefinite_article(get_err_type_str(s)) - ) %>% - sort() + sapply( + funcstrs, + function(s) prepend_indefinite_article(get_err_type_str(s)) + ) %>% sort() } get_err_type_str <- function(function_name_str) { diff --git a/man/overlayLegend.Rd b/man/overlayLegend.Rd index bb47983..fa2c646 100644 --- a/man/overlayLegend.Rd +++ b/man/overlayLegend.Rd @@ -83,6 +83,15 @@ being a custom ggplot object. It will not override or erase any additional layers that the user/other functions have added. To just remove the legend, see \link{removeLegend}. } +\details{ +The size legend on APackOfTheClones plots are simply a collection of +annotation layers of the \code{rect}, \code{text}, \code{circle} geoms. Therefore it +isn't quite a ggplot legend. In the actual ggplot object, the \verb{$layers} +element should all be named with an empty character \code{""}, and those +that comprise the annotation layers of the legend should be named whatever +\code{APackOfTheClones:::.ApotcLegendLayerName} is. Note that this is simply +an implementation detail that the user should not interfere with. +} \examples{ # create a plot with a legend apotc_plot <- vizAPOTC(get(data("combined_pbmc")), verbose = FALSE) @@ -90,9 +99,8 @@ apotc_plot <- vizAPOTC(get(data("combined_pbmc")), verbose = FALSE) # reposition the legend to top right overlayLegend(apotc_plot, legend_position = "top right") -# use different sizes and label -overlayLegend( - apotc_plot, +# use different sizes and label - may be nice to use the pipe +apotc_plot |> overlayLegend( legend_sizes = c(1, 3, 7, 9), legend_label = "odd sizes" )