-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add file * first setup minimal convplot * represent turns only and use talkr-specific names for data eg begin instead of xmin * remove participant from required aesthetics * fix issue from existing column nwords * add geom_token * fix namespace and ggproto docs * rename plot function and use geoms * add rank and frequency to token db * add geom tests * update docs for sourcecount * remove unused file * Update geom documentation with inherited parameters * Add additional options to default turn plot * comment out unused test * update plot customization options * Add geoms and default plot to workflow * ggplot should be loaded also for aes use
- Loading branch information
Showing
13 changed files
with
413 additions
and
47 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
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,50 @@ | ||
#' Plot individual tokens | ||
#' | ||
#' From a separate data frame containing tokenized data, plot individual tokens | ||
#' at their estimated time. Data must be provided separately, and should | ||
#' contain a column with the participant (y) and a column with the time (x). | ||
#' | ||
#' @param data A tokenized data frame (see `tokenize()`). | ||
#' @inheritParams ggplot2::layer | ||
#' @inheritParams ggplot2::geom_point | ||
#' @export | ||
geom_token <- function(data, mapping = NULL, | ||
stat = "identity", position = "identity", | ||
..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) { | ||
layer( | ||
data = data, | ||
mapping = mapping, | ||
geom = GeomToken, | ||
stat = stat, | ||
position = position, | ||
show.legend = show.legend, | ||
inherit.aes = inherit.aes, | ||
params = list(na.rm = na.rm, | ||
...) | ||
) | ||
} | ||
|
||
#' GeomToken | ||
#' | ||
#' @rdname ggplot2-ggproto | ||
#' @format NULL | ||
#' @usage NULL | ||
#' @export | ||
GeomToken <- ggproto( | ||
"GeomToken", Geom, | ||
required_aes = c("x", "y"), | ||
|
||
default_aes = aes( | ||
fill = "grey90", | ||
colour = "grey40", | ||
alpha = 1, | ||
size = 1, | ||
shape = 19, | ||
stroke = 1 | ||
), | ||
|
||
draw_panel = function(data, panel_params, coord, ...) { | ||
ggplot2::GeomPoint$draw_panel(data, panel_params, coord) | ||
} | ||
) | ||
|
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,56 @@ | ||
#' Plot a stretch of conversation | ||
#' | ||
#' Utterances are plotted as grey boxes, with frequently occurring tokens overlaid as colored dots. | ||
#' | ||
#' @param data a talkr dataset | ||
#' @param begin start time of the plot in seconds (defaults to 0) | ||
#' @param duration duration of the plot in seconds (defaults to 60) | ||
#' @param maxrank maximum rank of tokens to plot (defaults to 10) | ||
#' @param source name or number of the source to plot (defaults to 1, plotting the first source in the data) | ||
#' | ||
#' @return plot object | ||
#' @export | ||
plot_turns_tokens <- function(data, | ||
begin = 0, | ||
duration = 60, | ||
maxrank = 10, | ||
source = 1){ | ||
check_talkr(data) | ||
|
||
if(is.numeric(source)){ | ||
sourcenr <- min(source, length(unique(data$source))) | ||
source <- unique(data$source)[sourcenr] | ||
} | ||
data <- data[data$source == source,] | ||
|
||
tokens <- data |> | ||
tokenize() | ||
tokens <- tokens[tokens$rank < maxrank,] | ||
|
||
time_start <- begin * 1000 | ||
time_end <- time_start + duration * 1000 | ||
data <- data[data$begin > time_start & data$end < time_end,] | ||
|
||
uids_included <- unique(data$uid) | ||
tokens <- tokens[tokens$uid %in% uids_included,] | ||
|
||
p <- data |> | ||
ggplot2::ggplot(aes( | ||
x = .data$end, | ||
y = .data$participant)) + | ||
talkr::geom_turn(aes( | ||
begin = .data$begin, | ||
end = .data$end)) + | ||
talkr::geom_token(data = tokens, | ||
aes(x = .data$relative_time, | ||
y = .data$participant, | ||
color = .data$rank)) + | ||
talkr::theme_turnPlot() + | ||
ggplot2::xlab("time (ms)") + | ||
ggplot2::ggtitle(source) | ||
|
||
|
||
return(p) | ||
} | ||
|
||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.