-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'add-draw-key' into develop-0.5.7
- Loading branch information
Showing
17 changed files
with
281 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
Package: ggpp | ||
Type: Package | ||
Title: Grammar Extensions to 'ggplot2' | ||
Version: 0.5.6.9000 | ||
Date: 2024-03-03 | ||
Version: 0.5.6.9001 | ||
Date: 2024-03-04 | ||
Authors@R: | ||
c( | ||
person("Pedro J.", "Aphalo", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-3385-972X")), | ||
|
@@ -58,3 +58,45 @@ BugReports: https://github.com/aphalo/ggpp/issues | |
Encoding: UTF-8 | ||
RoxygenNote: 7.3.1 | ||
VignetteBuilder: knitr | ||
Collate: | ||
'annotate.r' | ||
'compute-npc.r' | ||
'dark-or-light.R' | ||
'example-data.R' | ||
'geom-grob.R' | ||
'ggpp-legend-draw.R' | ||
'utilities.R' | ||
'ggp2-margins.R' | ||
'geom-label-linked.r' | ||
'geom-label-npc.r' | ||
'geom-label-pairwise.r' | ||
'geom-margin-arrow.r' | ||
'geom-margin-grob.r' | ||
'geom-margin-point.r' | ||
'geom-plot.R' | ||
'geom-point-linked.r' | ||
'geom-quadrant-lines.R' | ||
'geom-table.R' | ||
'geom-text-linked.r' | ||
'geom-text-npc.r' | ||
'geom-text-pairwise.R' | ||
'ggpp.R' | ||
'position-nudge-center.R' | ||
'position-nudge-dodge.R' | ||
'position-nudge-dodge2.R' | ||
'position-nudge-jitter.R' | ||
'position-nudge-line.R' | ||
'position-nudge-stack.R' | ||
'position-nudge-to.R' | ||
'scale-continuous-npc.r' | ||
'stat-apply.R' | ||
'stat-dens1d-filter.r' | ||
'stat-dens1d-labels.r' | ||
'stat-dens2d-filter.r' | ||
'stat-dens2d-labels.r' | ||
'stat-format-table.R' | ||
'stat-functions.R' | ||
'stat-panel-counts.R' | ||
'stat-quadrant-counts.R' | ||
'try-data-frame.R' | ||
'weather-data.R' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#' Key glyphs for legends | ||
#' | ||
#' Each geom has an associated function that draws the key when the geom needs | ||
#' to be displayed in a legend. These functions are called `draw_key_*()`, where | ||
#' `*` stands for the name of the respective key glyph. The key glyphs can be | ||
#' customized for individual geoms by providing a geom with the `key_glyph` | ||
#' argument (see [`layer()`] or examples below.) | ||
#' | ||
#' @return A grid grob. | ||
#' @param data A single row data frame containing the scaled aesthetics to | ||
#' display in this key | ||
#' @param params A list of additional parameters supplied to the geom. | ||
#' @param size Width and height of key in mm. | ||
#' @examples | ||
#' p <- ggplot(economics, aes(date, psavert, color = "savings rate")) | ||
#' # key glyphs can be specified by their name | ||
#' p + geom_line(key_glyph = "timeseries") | ||
#' | ||
#' # key glyphs can be specified via their drawing function | ||
#' p + geom_line(key_glyph = draw_key_rect) | ||
#' | ||
#' @keywords internal | ||
#' @name ggpp_draw_key | ||
NULL | ||
|
||
#' @export | ||
#' @rdname ggpp_draw_key | ||
draw_key_text_s <- function(data, params, size) { | ||
data <- replace_null(unclass(data), label = "a", angle = 0) | ||
hjust <- ifelse(data$hjust %in% c("left", "middle", "right"), | ||
compute_just(data$hjust %||% 0.5), | ||
0.5) | ||
vjust <- ifelse(data$vjust %in% c("left", "middle", "right"), | ||
compute_just(data$vjust %||% 0.5), | ||
0.5) | ||
just <- rotate_just(data$angle, hjust, vjust) | ||
grob <- titleGrob( | ||
data$label, | ||
x = unit(just$hjust, "npc"), y = unit(just$vjust, "npc"), | ||
angle = data$angle, | ||
hjust = hjust, | ||
vjust = vjust, | ||
gp = gpar( | ||
col = ifelse(params$colour.target %in% c("text", "all"), | ||
alpha(data$colour %||% data$fill %||% params$default.colour %||% "black", | ||
data$alpha %||% params$default.alpha %||% 1), | ||
params$default.colour %||% "black"), | ||
fontfamily = data$family %||% "", | ||
fontface = data$fontface %||% 1, | ||
fontsize = (data$size %||% 3.88) * .pt | ||
), | ||
margin = margin(0.1, 0.1, 0.1, 0.1, unit = "lines"), | ||
margin_x = TRUE, margin_y = TRUE | ||
) | ||
attr(grob, "width") <- convertWidth(grobWidth(grob), "cm", valueOnly = TRUE) | ||
attr(grob, "height") <- convertHeight(grobHeight(grob), "cm", valueOnly = TRUE) | ||
grob | ||
} | ||
|
||
#' @export | ||
#' @rdname ggpp_draw_key | ||
draw_key_label_s <- function(data, params, size) { | ||
data <- replace_null(unclass(data), label = "a", angle = 0) | ||
params$label.size <- params$label.size %||% 0.25 | ||
hjust <- ifelse(data$hjust %in% c("left", "middle", "right"), | ||
compute_just(data$hjust %||% 0.5), | ||
0.5) | ||
vjust <- ifelse(data$vjust %in% c("left", "middle", "right"), | ||
compute_just(data$vjust %||% 0.5), | ||
0.5) | ||
just <- rotate_just(data$angle, hjust, vjust) | ||
padding <- rep(params$label.padding %||% unit(0.25, "lines"), length.out = 4) | ||
descent <- font_descent( | ||
family = data$family %||% "", | ||
face = data$fontface %||% 1, | ||
size = data$size %||% 3.88 | ||
) | ||
grob <- labelGrob( | ||
data$label, | ||
x = unit(just$hjust, "npc"), | ||
y = unit(just$vjust, "npc") + descent, | ||
angle = data$angle, | ||
just = c(hjust, vjust), | ||
padding = padding, | ||
r = params$label.r %||% unit(0.15, "lines"), | ||
text.gp = gpar( | ||
col = ifelse(params$colour.target %in% c("text", "all"), | ||
alpha(data$colour %||% data$fill %||% params$default.colour %||% "black", | ||
data$alpha%||% params$default.alpha %||% 1), | ||
params$default.colour %||% "black"), | ||
fontfamily = data$family %||% "", | ||
fontface = data$fontface %||% 1, | ||
fontsize = (data$size %||% 3.88) * .pt | ||
), | ||
rect.gp = gpar( | ||
col = if (isTRUE(all.equal(params$label.size, 0))) { | ||
NA | ||
} else { | ||
ifelse(params$colour.target %in% c("box", "all"), | ||
alpha(data$colour %||% data$fill %||% params$default.colour %||% "black", | ||
data$alpha %||% params$default.alpha %||% 1), | ||
params$default.colour %||% "black") | ||
}, | ||
fill = alpha(data$fill %||% "white", | ||
data$alpha %||% params$default.alpha %||% 1), | ||
lwd = (data$linewidth %||% 0.25) * ggplot2::.stroke, | ||
lty = data$linetype %||% "solid" | ||
) | ||
) | ||
angle <- deg2rad(data$angle %||% 0) | ||
text <- grob$children[[2]] | ||
width <- convertWidth(grobWidth(text), "cm", valueOnly = TRUE) | ||
height <- convertHeight(grobHeight(text), "cm", valueOnly = TRUE) | ||
x <- c(0, 0, width, width) | ||
y <- c(0, height, height, 0) | ||
attr(grob, "width") <- diff(range(x * cos(angle) - y * sin(angle))) | ||
attr(grob, "height") <- diff(range(x * sin(angle) + y * cos(angle))) | ||
grob | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.