From 9722173e0aba4a18337d0153a3ec5a886f62514e Mon Sep 17 00:00:00 2001 From: sean-connelly-cmap <156253293+sean-connelly-cmap@users.noreply.github.com> Date: Tue, 13 Aug 2024 09:31:07 -0500 Subject: [PATCH] push text_repel change --- DESCRIPTION | 2 +- NAMESPACE | 4 ++-- R/cmapplot_globals.R | 2 +- R/default_aes.R | 2 +- ...stonly_new.R => geom_text_lastonly_repel.R} | 18 +++++++++--------- man/customproto.Rd | 6 +++--- ...only_new.Rd => geom_text_lastonly_repel.Rd} | 16 ++++++++-------- 7 files changed, 25 insertions(+), 25 deletions(-) rename R/{geom_text_lastonly_new.R => geom_text_lastonly_repel.R} (98%) rename man/{geom_text_lastonly_new.Rd => geom_text_lastonly_repel.Rd} (95%) diff --git a/DESCRIPTION b/DESCRIPTION index 66a632c..f2d8c79 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: cmapplot Title: CMAP Themes and Color Palettes -Version: 1.2.1 +Version: 1.2.2 Authors@R: c( person("Daniel", "Comeaux", role = c("aut", "cre"), diff --git a/NAMESPACE b/NAMESPACE index 620b843..d64c2ae 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,7 +6,7 @@ export(GeomPointLast) export(GeomRecessions) export(GeomRecessionsText) export(GeomTextLast) -export(GeomTextLastNew) +export(GeomTextLastRepel) export(PositionNudgeRepel) export(abbr_years) export(apply_cmap_default_aes) @@ -26,7 +26,7 @@ export(fetch_pal) export(finalize_plot) export(geom_recessions) export(geom_text_lastonly) -export(geom_text_lastonly_new) +export(geom_text_lastonly_repel) export(get_cmapplot_global) export(get_cmapplot_globals) export(gg_lwd_convert) diff --git a/R/cmapplot_globals.R b/R/cmapplot_globals.R index 50ce171..22c384a 100644 --- a/R/cmapplot_globals.R +++ b/R/cmapplot_globals.R @@ -114,7 +114,7 @@ cmapplot_globals$geoms_that_change <- c( "Line", "Text", "TextLast", - "TextLastNew", + "TextLastRepel", "PointLast", "RecessionsText" ) diff --git a/R/default_aes.R b/R/default_aes.R index c7c4da5..59953a5 100644 --- a/R/default_aes.R +++ b/R/default_aes.R @@ -29,7 +29,7 @@ init_cmap_default_aes <- function () { size = cmapplot_globals$fsize$M/ggplot2::.pt, # pt-to-mm conversion colour = cmapplot_globals$colors$blackish ), - TextLastNew = list( + TextLastRepel = list( family = cmapplot_globals$font$strong$family, fontface = ifelse(cmapplot_globals$font$strong$face == "bold", 2, 1), size = cmapplot_globals$fsize$M/ggplot2::.pt, # pt-to-mm conversion diff --git a/R/geom_text_lastonly_new.R b/R/geom_text_lastonly_repel.R similarity index 98% rename from R/geom_text_lastonly_new.R rename to R/geom_text_lastonly_repel.R index 1bf0b97..77031d5 100644 --- a/R/geom_text_lastonly_new.R +++ b/R/geom_text_lastonly_repel.R @@ -1,6 +1,6 @@ #' Text (Last Only) New #' -#' Label only the last point(s) on a plot. \code{geom_text_lastonly_new()} can be +#' Label only the last point(s) on a plot. \code{geom_text_lastonly_repel()} can be #' used instead of \code{ggplot2::geom_text()} when only the last point(s) #' should be labeled. This is accomplished by identifying the maximum value of #' \code{x} in \code{data} and applying a filter to omit records where \code{x} @@ -108,7 +108,7 @@ #' labs(title="Random lines") + #' scale_y_continuous("Percentage of absolutely nothing") + #' scale_x_continuous("Year") + -#' geom_text_lastonly_new() +#' geom_text_lastonly_repel() #' #' # With points, label formatting and x-axis expansion #' ggplot(df, aes(x=year, y=value, color=var, label=sprintf("%.1f%%", 100*value))) + @@ -116,10 +116,10 @@ #' labs(title="Random lines") + #' scale_y_continuous("Percentage of absolutely nothing", labels=scales::percent) + #' scale_x_continuous("Year", expand=expansion(mult=c(0.05, 0.10))) + -#' geom_text_lastonly_new(add_points=TRUE, text_aes=list(fontface="bold"), point_aes=list(size=2.5)) +#' geom_text_lastonly_repel(add_points=TRUE, text_aes=list(fontface="bold"), point_aes=list(size=2.5)) #' #' @export -geom_text_lastonly_new <- function(mapping = NULL, data = NULL, +geom_text_lastonly_repel <- function(mapping = NULL, data = NULL, stat = "identity", position = NULL, parse = FALSE, box.padding = 0.25, @@ -176,7 +176,7 @@ geom_text_lastonly_new <- function(mapping = NULL, data = NULL, data = data, mapping = mapping, stat = stat, - geom = GeomTextLastNew, + geom = GeomTextLastRepel, position = position_lab, show.legend = show.legend, inherit.aes = inherit.aes, @@ -224,8 +224,8 @@ NULL #' @format NULL #' @usage NULL #' @export -GeomTextLastNew <- ggproto( - "GeomTextLastNew", Geom, +GeomTextLastRepel <- ggproto( + "GeomTextLastRepel", Geom, required_aes = c("x", "y"), default_aes = aes( @@ -330,7 +330,7 @@ GeomTextLastNew <- ggproto( data$hjust <- compute_just(data$hjust, data$x, data$y, data$angle) } - ggname("geom_text_lastonly_new", gTree( + ggname("geom_text_lastonly_repel", gTree( limits = limits, data = data, lab = data$label, @@ -671,7 +671,7 @@ makeTextRepelGrobs <- function( grobs } -# GeomTextLastNew helper functions +# GeomTextLastRepel helper functions # copied from ggplot2 compute_just <- function(just, a, b = a, angle = 0) { # As justification direction is relative to the text, not the plotting area diff --git a/man/customproto.Rd b/man/customproto.Rd index 3142459..86f9b16 100644 --- a/man/customproto.Rd +++ b/man/customproto.Rd @@ -1,6 +1,6 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/geom_recessions.R, R/geom_text_lastonly.R, -% R/geom_text_lastonly_new.R +% R/geom_text_lastonly_repel.R \docType{data} \name{customproto} \alias{customproto} @@ -8,7 +8,7 @@ \alias{GeomRecessionsText} \alias{GeomTextLast} \alias{GeomPointLast} -\alias{GeomTextLastNew} +\alias{GeomTextLastRepel} \title{Custom ggproto classes} \description{ The \code{cmapplot} package contains a few custom ggproto objects. For the @@ -31,7 +31,7 @@ objects. For more information about these, see \item \code{GeomPointLast}: Add points to plot for maximum x-value in dataset only. -\item \code{GeomTextLastNew}: Add text to plot for maximum x-value in dataset only. +\item \code{GeomTextLastRepel}: Add text to plot for maximum x-value in dataset only. \item \code{GeomPointLast}: Add points to plot for maximum x-value in dataset only. diff --git a/man/geom_text_lastonly_new.Rd b/man/geom_text_lastonly_repel.Rd similarity index 95% rename from man/geom_text_lastonly_new.Rd rename to man/geom_text_lastonly_repel.Rd index 1f354a2..076ef33 100644 --- a/man/geom_text_lastonly_new.Rd +++ b/man/geom_text_lastonly_repel.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/geom_text_lastonly_new.R -\name{geom_text_lastonly_new} -\alias{geom_text_lastonly_new} +% Please edit documentation in R/geom_text_lastonly_repel.R +\name{geom_text_lastonly_repel} +\alias{geom_text_lastonly_repel} \title{Text (Last Only) New} \usage{ -geom_text_lastonly_new( +geom_text_lastonly_repel( mapping = NULL, data = NULL, stat = "identity", @@ -19,7 +19,7 @@ geom_text_lastonly_new( max.time = 0.5, max.iter = 10000, max.overlaps = getOption("ggrepel.max.overlaps", default = 10), - nudge_x = 0.25, + nudge_x = 0.4, nudge_y = 0, xlim = c(NA, NA), ylim = c(NA, NA), @@ -124,7 +124,7 @@ Note that if \code{add_points = FALSE}, additional parameters can be passed to the text geom here, rather than in \code{text_aes}, without breaking.} } \description{ -Label only the last point(s) on a plot. \code{geom_text_lastonly_new()} can be +Label only the last point(s) on a plot. \code{geom_text_lastonly_repel()} can be used instead of \code{ggplot2::geom_text()} when only the last point(s) should be labeled. This is accomplished by identifying the maximum value of \code{x} in \code{data} and applying a filter to omit records where \code{x} @@ -153,7 +153,7 @@ ggplot(df, aes(x=year, y=value, color=var)) + labs(title="Random lines") + scale_y_continuous("Percentage of absolutely nothing") + scale_x_continuous("Year") + - geom_text_lastonly_new() + geom_text_lastonly_repel() # With points, label formatting and x-axis expansion ggplot(df, aes(x=year, y=value, color=var, label=sprintf("\%.1f\%\%", 100*value))) + @@ -161,6 +161,6 @@ ggplot(df, aes(x=year, y=value, color=var, label=sprintf("\%.1f\%\%", 100*value) labs(title="Random lines") + scale_y_continuous("Percentage of absolutely nothing", labels=scales::percent) + scale_x_continuous("Year", expand=expansion(mult=c(0.05, 0.10))) + - geom_text_lastonly_new(add_points=TRUE, text_aes=list(fontface="bold"), point_aes=list(size=2.5)) + geom_text_lastonly_repel(add_points=TRUE, text_aes=list(fontface="bold"), point_aes=list(size=2.5)) }