Skip to content

Commit

Permalink
Merge pull request #122 from AnttiRask/pluck_refactor
Browse files Browse the repository at this point in the history
Refactored the visualize_walks function
  • Loading branch information
spsanderson authored Oct 3, 2024
2 parents 3e7815a + 3ad822e commit f480d34
Showing 1 changed file with 15 additions and 26 deletions.
41 changes: 15 additions & 26 deletions R/plt-visualize-walks.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ visualize_walks <- function(.data, .alpha = 0.7, .interactive = FALSE, .pluck =
# Retrieve the attributes of the data (e.g., function name, number of walks, etc.)
atb <- attributes(.data)

# Define plot options for ggiraph
plot_options <- list(
# Customize hover effect
ggiraph::opts_hover(css = "stroke:black;stroke-width:2pt;"),
# Customize hover-out effect
ggiraph::opts_hover_inv(css = "opacity:0.4;"),
# Place toolbar on top right
ggiraph::opts_toolbar(position = "topright"),
# Customize tooltip
ggiraph::opts_tooltip(offx = 200, offy = 5, use_cursor_pos = FALSE, opacity = 0.7),
# Enable zoom
ggiraph::opts_zoom(max = 5)
)

# Function to generate a plot for a given y-variable in the data
generate_plot <- function(y_var) {

Expand Down Expand Up @@ -201,18 +215,7 @@ visualize_walks <- function(.data, .alpha = 0.7, .interactive = FALSE, .pluck =
return(
ggiraph::girafe(
ggobj = plucked_plot + plot_theme,
options = list(
ggiraph::opts_hover(css = "stroke:black;stroke-width:2pt;"),
ggiraph::opts_hover_inv(css = "opacity:0.4;"),
ggiraph::opts_toolbar(position = "topright"),
ggiraph::opts_tooltip(
offx = 200,
offy = 5,
use_cursor_pos = FALSE,
opacity = 0.7
),
ggiraph::opts_zoom(max = 5)
)
options = plot_options
)
)
}
Expand All @@ -235,20 +238,6 @@ visualize_walks <- function(.data, .alpha = 0.7, .interactive = FALSE, .pluck =
# Patchwork for the interactive version of the visualization
} else {

# Define plot options for ggiraph
plot_options <- list(
# Customize hover effect
ggiraph::opts_hover(css = "stroke:black;stroke-width:2pt;"),
# Customize hover-out effect
ggiraph::opts_hover_inv(css = "opacity:0.4;"),
# Place toolbar on top right
ggiraph::opts_toolbar(position = "topright"),
# Customize tooltip
ggiraph::opts_tooltip(offx = 200, offy = 5, use_cursor_pos = FALSE, opacity = 0.7),
# Enable zoom
ggiraph::opts_zoom(max = 5)
)

# Combine plots using patchwork for interactive visualization
combined_plot <- if (length(plots) > 1) {
ggiraph::girafe(
Expand Down

0 comments on commit f480d34

Please sign in to comment.