1919# ' value determines order of the subjects displayed on the y-axis.
2020# ' @param tooltip_vars (`character` or `NULL`) A vector of column names to be displayed in the tooltip.
2121# ' If `NULL`, default tooltip is created.
22- # ' @param size_var (`character(1)` or `NULL`) If provided, this numeric column from the `plot_dataname`
23- # ' will be used to determine the size of the points. If `NULL`, a fixed size based on the `point_size` is used.
24- # ' @param point_size (`numeric(1)`) Default point size of the points in the plot.
22+ # ' @param point_size (`numeric(1)` or `named numeric`) Default point size of the points in the plot.
23+ # ' If `point_size` is a named numeric vector, it should be named by levels of `color_var` column.
2524# ' @param point_colors (`named character`) valid color names (see [colors()]) or hex-colors named
2625# ' by levels of `color_var` column.
2726# ' @param point_symbols (`named character`) valid plotly symbol name named by levels of `color_var` column.
@@ -82,7 +81,6 @@ tm_g_swimlane <- function(label = "Swimlane",
8281 group_var ,
8382 sort_var = NULL ,
8483 tooltip_vars = NULL ,
85- size_var = NULL ,
8684 point_size = 10 ,
8785 point_colors = character (0 ),
8886 point_symbols = character (0 ),
@@ -119,7 +117,6 @@ tm_g_swimlane <- function(label = "Swimlane",
119117 color_var = color_var ,
120118 group_var = group_var ,
121119 sort_var = sort_var ,
122- size_var = size_var ,
123120 point_size = point_size ,
124121 point_colors = point_colors ,
125122 point_symbols = point_symbols ,
@@ -164,7 +161,6 @@ srv_g_swimlane <- function(id,
164161 color_var ,
165162 group_var ,
166163 sort_var = time_var ,
167- size_var = NULL ,
168164 point_size = 10 ,
169165 point_colors ,
170166 point_symbols ,
@@ -203,7 +199,6 @@ srv_g_swimlane <- function(id,
203199 color_var = input $ color_var ,
204200 group_var = input $ group_var ,
205201 sort_var = input $ sort_var ,
206- size_var = size_var ,
207202 point_size = point_size ,
208203 colors = color_inputs(),
209204 symbols = adjusted_symbols ,
@@ -217,7 +212,6 @@ srv_g_swimlane <- function(id,
217212 color_var = color_var ,
218213 group_var = group_var ,
219214 sort_var = sort_var ,
220- size_var = size_var ,
221215 point_size = point_size ,
222216 colors = colors ,
223217 symbols = symbols ,
@@ -307,18 +301,12 @@ srv_g_swimlane <- function(id,
307301# ' @export
308302swimlanely <- function (
309303 data , time_var , subject_var , color_var , group_var , sort_var ,
310- colors , symbols , height , tooltip_vars = NULL , size_var = NULL , point_size = 10 ) {
304+ colors , symbols , height , tooltip_vars = NULL , point_size = 10 ) {
311305 subject_var_label <- .get_column_label(data , subject_var )
312306 time_var_label <- .get_column_label(data , time_var )
313307 data <- data | >
314308 dplyr :: mutate(customdata = dplyr :: row_number())
315309
316- if (is.null(size_var )) {
317- size <- point_size
318- } else {
319- size <- stats :: as.formula(sprintf(" ~%s" , size_var ))
320- }
321-
322310 # forcats::fct_reorder doesn't seem to work here
323311 subject_levels <- data %> %
324312 dplyr :: group_by(!! as.name(subject_var )) %> %
@@ -328,6 +316,19 @@ swimlanely <- function(
328316 dplyr :: pull(!! as.name(subject_var ))
329317 data [[subject_var ]] <- factor (data [[subject_var ]], levels = subject_levels )
330318
319+ min_size <- min(point_size , na.rm = TRUE )
320+
321+ if (length(point_size ) > 1 ) {
322+ data <- data %> %
323+ dplyr :: mutate(
324+ size_var = ifelse(
325+ as.character(color_var ) %in% names(point_size ),
326+ point_size [as.character(color_var )],
327+ min_size
328+ )
329+ )
330+ }
331+
331332 data %> %
332333 dplyr :: mutate(
333334 !! as.name(color_var ) : = factor (!! as.name(color_var ), levels = names(colors )),
@@ -367,7 +368,7 @@ swimlanely <- function(
367368 y = stats :: as.formula(sprintf(" ~%s" , subject_var )),
368369 color = stats :: as.formula(sprintf(" ~%s" , color_var )),
369370 symbol = stats :: as.formula(sprintf(" ~%s" , color_var )),
370- size = size ,
371+ size = ~ size_var ,
371372 text = ~ tooltip ,
372373 hoverinfo = " text"
373374 ) %> %
0 commit comments