Skip to content

Commit

Permalink
Fix label scaling in path plots
Browse files Browse the repository at this point in the history
  • Loading branch information
maltelueken committed Oct 25, 2023
1 parent 1c7508a commit bd2c5fe
Show file tree
Hide file tree
Showing 193 changed files with 1,901 additions and 1,897 deletions.
12 changes: 8 additions & 4 deletions R/classicProcess.R
Original file line number Diff line number Diff line change
Expand Up @@ -1914,7 +1914,6 @@ ClassicProcess <- function(jaspResults, dataset = NULL, options) {

# Scale layout so that there is always one full step between each pos
decimalPos <- layout[!nodeIsHelper,] %% 1
labelScale <- 30

# Path plots look better without scaling x-axis
# if (any(na.omit(decimalPos[,1]) > 0)) {
Expand All @@ -1923,9 +1922,13 @@ ClassicProcess <- function(jaspResults, dataset = NULL, options) {
if (any(na.omit(decimalPos[,2]) > 0)) {
yScale <- (1/min(decimalPos[,2][decimalPos[,2] > 0], na.rm = TRUE))
layout[,2] <- layout[,2] * yScale
labelScale <- labelScale * yScale
}

xRange <- diff(range(layout[,1], na.rm = TRUE))
yRange <- diff(range(layout[,2], na.rm = TRUE))

labelScale <- pmax(xRange, yRange)

plotLayout <- ggraph::create_layout(graph, layout = layout[match(igraph::V(graph)$name, rownames(layout)), , drop = FALSE])

if (type == "statistical") {
Expand Down Expand Up @@ -1955,13 +1958,14 @@ ClassicProcess <- function(jaspResults, dataset = NULL, options) {
arrow = ggplot2::arrow(length = grid::unit(0.05, "native")),
start_cap = ggraph::square(nodeSize, unit = "native"), # Arrow start has always margin
angle_calc = "along",
label_size = 7/sqrt(labelScale),
label_dodge = grid::unit(0.025, "native"),
label_push = grid::unit(-0.025, "native")
label_push = grid::unit(-0.01, "native")
) +
# Add abbreviated node lables with dummy alpha variable to display them in legend
ggraph::geom_node_text(
ggplot2::aes(label = nodeLabelsAbbr, alpha = nodeAlpha),
size = labelScale/(sum(!nodeIsHelper) + options[["pathPlotsLabelLength"]] - 3)
size = 20/(labelScale + options[["pathPlotsLabelLength"]] - 3)
) +
# Make helper nodes transparent and hide color from legend
ggplot2::scale_color_manual(values = c("black", "transparent"), guide = NULL) +
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit bd2c5fe

Please sign in to comment.