Skip to content

Commit

Permalink
represent turns only and use talkr-specific names for data eg begin i…
Browse files Browse the repository at this point in the history
…nstead of xmin
  • Loading branch information
bvreede committed Jan 9, 2024
1 parent 69cd88c commit f8eda58
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
37 changes: 22 additions & 15 deletions R/geom_turn.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
#' @param stat The statistical transformation to use on the data for this layer, either as a ggproto Geom subclass or as a string naming the stat stripped of the stat_ prefix (e.g. "count" rather than "stat_count")
#' @param position Position adjustment, either as a string naming the adjustment (e.g. "jitter" to use position_jitter), or the result of a call to a position adjustment function. Use the latter if you need to change the settings of the adjustment.
#' @param na.rm If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.
#' @param height The height of the rectangles representing turns
#' @param show.legend logical. Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes. It can also be a named logical vector to finely select the aesthetics to display.
#' @param inherit.aes If FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g. borders().
#' @param ... Other arguments passed on to layer(). These are often aesthetics, used to set an aesthetic to a fixed value, like colour = "red" or size = 3. They may also be parameters to the paired geom/stat.
#' @export
#' @rdname geom_turn
geom_turn <- function(mapping = NULL, data = NULL,
stat = "identity", position = "identity",
..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) {
..., na.rm = FALSE, height = 0.8, show.legend = NA, inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
Expand All @@ -22,6 +23,7 @@ geom_turn <- function(mapping = NULL, data = NULL,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(na.rm = na.rm,
height = height,

Check warning on line 26 in R/geom_turn.R

View check run for this annotation

Codecov / codecov/patch

R/geom_turn.R#L26

Added line #L26 was not covered by tests
...)
)
}
Expand All @@ -34,26 +36,31 @@ geom_turn <- function(mapping = NULL, data = NULL,
#' @export
GeomTurn <- ggproto(
"GeomTurn", Geom,
required_aes = c("xmin", "xmax", "ymin", "ymax", "xpoint", "ypoint", "fillpoint"),
required_aes = c("begin", "end", "participant"),

default_aes = aes(
fill = "lightgrey",
fill = "grey80",
linewidth = 0,
alpha = 1,
colour = "white", # geom_point
size = 2,
shape = 21,
stroke = 1
alpha = 1
),

draw_panel = function(data, panel_params, coord, ...) {
rect_data <- transform(data, xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax)
point_data <- transform(data, x = xpoint, y = -ypoint, fill = fillpoint)
extra_params = c("na.rm", "height"),

setup_data = function(data, params) {
data$participant_int <- as.integer(as.factor(data$participant))
data$ymin <- data$participant_int - (0.5*params$height)
data$ymax <- data$participant_int + (0.5*params$height)

grid::grobTree(
ggplot2::GeomRect$draw_panel(rect_data, panel_params, coord),
ggplot2::GeomPoint$draw_panel(point_data, panel_params, coord)
)
data
},

draw_panel = function(data, panel_params, coord, ...) {
rect_data <- transform(data,
xmin = begin,
xmax = end,
ymin = ymin,
ymax = ymax)
ggplot2::GeomRect$draw_panel(rect_data, panel_params, coord)
}
)

3 changes: 3 additions & 0 deletions man/geom_turn.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f8eda58

Please sign in to comment.