Skip to content

Commit

Permalink
Merge pull request #19 from rnabioco/new_args
Browse files Browse the repository at this point in the history
* Simplified arguments, closes #18
  • Loading branch information
sheridar authored Sep 3, 2021
2 parents 2f86c68 + f3f285c commit 2a11a5f
Show file tree
Hide file tree
Showing 23 changed files with 80 additions and 1,482 deletions.
29 changes: 0 additions & 29 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,6 @@ export(enquo)
export(enquos)
export(expr)
export(geom_point_trace)
export(scale_trace_alpha)
export(scale_trace_alpha_binned)
export(scale_trace_alpha_continuous)
export(scale_trace_alpha_discrete)
export(scale_trace_alpha_manual)
export(scale_trace_alpha_ordinal)
export(scale_trace_color_binned)
export(scale_trace_color_continuous)
export(scale_trace_color_discrete)
export(scale_trace_color_hue)
export(scale_trace_color_manual)
export(scale_trace_colour_binned)
export(scale_trace_colour_continuous)
export(scale_trace_colour_discrete)
export(scale_trace_colour_hue)
export(scale_trace_colour_manual)
export(scale_trace_linetype)
export(scale_trace_linetype_binned)
export(scale_trace_linetype_continuous)
export(scale_trace_linetype_discrete)
export(scale_trace_linetype_manual)
export(scale_trace_size)
export(scale_trace_size_area)
export(scale_trace_size_binned)
export(scale_trace_size_binned_area)
export(scale_trace_size_continuous)
export(scale_trace_size_discrete)
export(scale_trace_size_manual)
export(scale_trace_size_ordinal)
export(sym)
export(syms)
import(ggplot2)
Expand Down
12 changes: 7 additions & 5 deletions R/a-legend-draw.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ draw_key_point_trace <- function(data, params, size) {
data$trace_shape <- translate_trace_shape(data$shape)
data <- calculate_trace_size(data)

pt_stroke <- 0.5

g_trace <- grid::pointsGrob(
0.5, 0.5,
pch = data$trace_shape,
gp = grid::gpar(
col = alpha(data$trace_colour %||% "black", data$trace_alpha),
lty = data$trace_linetype %||% 1,
col = alpha(data$colour %||% "black", 1),
lty = data$linetype %||% 1,
fontsize = data$trace_fontsize,
lwd = data$trace_lwd
)
Expand All @@ -48,9 +50,9 @@ draw_key_point_trace <- function(data, params, size) {
0.5, 0.5,
pch = data$shape,
gp = grid::gpar(
col = alpha(data$colour %||% "black", data$alpha),
fontsize = (data$size %||% 1.5) * .pt + (data$stroke %||% 0.5) * .stroke / 2,
lwd = (data$stroke %||% 0.5) * .stroke / 2
col = alpha(data$fill %||% "white", data$alpha),
fontsize = (data$size %||% 1.5) * .pt + pt_stroke * .stroke / 2,
lwd = pt_stroke * .stroke / 2
)
)

Expand Down
62 changes: 29 additions & 33 deletions R/geom-point-trace.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#' subset of data points can be outlined by passing a predicate. This must
#' evaluate to `TRUE` or `FALSE` within the context of the input data.
#' @param background_color Color to use for background points when a predicate
#' is passed to `trace_position`. If NULL, the original point color will be
#' is passed to `trace_position`. If NULL, the original fill color will be
#' used.
#' @param na.rm If `FALSE`, the default, missing values are removed with a
#' warning. If `TRUE`, missing values are silently removed.
Expand Down Expand Up @@ -82,22 +82,19 @@ geom_point_trace <- function(mapping = NULL, data = NULL, stat = "identity", pos
data <- ggplot2::fortify(~ subset(.x, eval(trace_expr)))
}

# For the background points, need to remove the trace parameters before
# generating GeomPoint layer, otherwise get argument warning
bkgd_params <- list(na.rm = na.rm, ...)
bkgd_params <- bkgd_params[!grepl("^trace_", names(bkgd_params))]
# Adjust parameters for background points
bkgd_params <- list(na.rm = na.rm, ...)
bkgd_params$color <- NA

if (!is.null(background_color)) {
bkgd_params$colour <- background_color
bkgd_params$fill <- background_color
}

bkgd_mapping <- mapping[!grepl("^trace_", names(mapping))]

bkgd_lyr <- ggplot2::layer(
bkgd_lyr <- layer(
data = bkgd_data,
mapping = bkgd_mapping,
mapping = mapping,
stat = stat,
geom = ggplot2::GeomPoint,
geom = GeomPointTrace,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
Expand Down Expand Up @@ -151,21 +148,16 @@ GeomPointTrace <- ggplot2::ggproto(

required_aes = c("x", "y"),

non_missing_aes = c(
"size", "shape", "colour",
"trace_size", "trace_linetype"
),
non_missing_aes = c("size", "shape", "fill"),

default_aes = ggplot2::aes(
shape = 19,
colour = "white",
size = 1.5,
stroke = 0.5,
alpha = NA,
trace_color = "black",
trace_size = 1,
trace_linetype = 1,
trace_alpha = NA
shape = 19,
colour = "black",
fill = "white",
size = 1.5,
stroke = 1,
linetype = 1,
alpha = NA
),

draw_group = function(self, data, panel_params, coord, na.rm = FALSE) {
Expand All @@ -183,20 +175,22 @@ GeomPointTrace <- ggplot2::ggproto(
coords$x, coords$y,
pch = coords$trace_shape,
gp = grid::gpar(
col = alpha(coords$trace_colour, coords$trace_alpha),
lty = coords$trace_linetype,
col = alpha(coords$colour, 1),
lty = coords$linetype,
fontsize = coords$trace_fontsize,
lwd = coords$trace_lwd
)
)

pt_stroke <- 0.5

g_points <- grid::pointsGrob(
coords$x, coords$y,
pch = coords$shape,
gp = grid::gpar(
col = alpha(coords$colour, coords$alpha),
fontsize = coords$size * .pt + coords$stroke * .stroke / 2,
lwd = coords$stroke * .stroke / 2
col = alpha(coords$fill, coords$alpha),
fontsize = coords$size * .pt + pt_stroke * .stroke / 2,
lwd = pt_stroke * .stroke / 2
)
)

Expand Down Expand Up @@ -303,17 +297,19 @@ translate_shape_string <- function(shape_string) {
calculate_trace_size <- function(data) {
pch_open <- 0:14

pt_stroke <- 0.5

pch <- data$shape

# Calculate fontsize for closed shapes
fontsize <- data$size * .pt + data$stroke * .stroke / 2
fontsize <- data$size * .pt + pt_stroke * .stroke / 2

fontsize[!pch %in% pch_open] <- fontsize[!pch %in% pch_open] + data$trace_size * .stroke / 2
fontsize[!pch %in% pch_open] <- fontsize[!pch %in% pch_open] + data$stroke * .stroke / 2

# Calculate lwd for open shapes
lwd <- data$trace_size * .stroke / 2
lwd <- data$stroke * .stroke / 2

lwd[pch %in% pch_open] <- lwd[pch %in% pch_open] * 2 + (data$stroke * .stroke / 2)
lwd[pch %in% pch_open] <- lwd[pch %in% pch_open] * 2 + (pt_stroke * .stroke / 2)

# Add results to data
data$trace_fontsize <- fontsize
Expand Down
44 changes: 0 additions & 44 deletions R/scale-trace-alpha.R

This file was deleted.

101 changes: 0 additions & 101 deletions R/scale-trace-colour.R

This file was deleted.

Loading

0 comments on commit 2a11a5f

Please sign in to comment.