Skip to content

Commit

Permalink
Add legend for node color in path plots
Browse files Browse the repository at this point in the history
  • Loading branch information
maltelueken committed Oct 9, 2023
1 parent b528fcb commit 9fdc197
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
25 changes: 16 additions & 9 deletions R/classicProcess.R
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,7 @@ procModelGraphSingleModel <- function(modelOptions, globalDependent, options) {

procPathPlot <- createJaspPlot(title = gettext("Conceptual path plot"), height = 320, width = 480)
procPathPlot$dependOn(
options = c("pathPlotsLegend", "pathPlotsLabelLength", "pathPlotsColor", "pathPlotsColorPalette"),
options = c("pathPlotsLegendLabels", "pathPlotsLegendColor", "pathPlotsLabelLength", "pathPlotsColor", "pathPlotsColorPalette"),
nestedOptions = list(c("processModels", as.character(modelIdx), "conceptualPathPlot"))
)
container[["conceptPathPlot"]] <- procPathPlot
Expand All @@ -1663,7 +1663,7 @@ procModelGraphSingleModel <- function(modelOptions, globalDependent, options) {

procPathPlot <- createJaspPlot(title = gettext("Statistical path plot"), height = 320, width = 480)
procPathPlot$dependOn(
options = c("statisticalPathPlotsParameterEstimates", "pathPlotsLegend", "pathPlotsLabelLength", "pathPlotsColor", "pathPlotsColorPalette"),
options = c("statisticalPathPlotsParameterEstimates", "pathPlotsLegendLabels", "pathPlotsLegendColor", "pathPlotsLabelLength", "pathPlotsColor", "pathPlotsColorPalette"),
nestedOptions = list(c("processModels", as.character(modelIdx), "statisticalPathPlot"))
)
container[["statPathPlot"]] <- procPathPlot
Expand Down Expand Up @@ -2013,13 +2013,13 @@ procModelGraphSingleModel <- function(modelOptions, globalDependent, options) {
nodeVis[nodeLabels == ""] = 1

# Create dummy alpha variable for nodes (nessecary for creating the legend)
nodeAlpha <- if (options[["pathPlotsLegend"]]) nodeLabels else NULL
nodeAlpha <- if (options[["pathPlotsLegendLabels"]]) nodeLabels else NULL

# Create node type variable for coloring
nodeType <- as.factor(ifelse(nodeLabels %in% decodeColNames(mediators), 0,
ifelse(nodeLabels %in% decodeColNames(mods) | grepl(":", nodeLabels), 1,
ifelse(nodeLabels %in% decodeColNames(independent), 2,
ifelse(nodeLabels %in% decodeColNames(dependent), 3, 4)
nodeType <- as.factor(ifelse(nodeLabels %in% decodeColNames(mediators), "Mediator",
ifelse(nodeLabels %in% decodeColNames(mods) | grepl(":", nodeLabels), "Moderator",
ifelse(nodeLabels %in% decodeColNames(independent), "Independent",
ifelse(nodeLabels %in% decodeColNames(dependent), "Dependent", NA)
)
)
))
Expand Down Expand Up @@ -2076,9 +2076,16 @@ procModelGraphSingleModel <- function(modelOptions, globalDependent, options) {
) +
# Make helper nodes transparent and hide color from legend
ggplot2::scale_color_manual(values = c("black", "transparent"), guide = NULL) +
ggplot2::scale_fill_manual(values = colorPalette, guide = NULL)
ggplot2::scale_fill_manual(
values = colorPalette,
# Remove helper node fill color (transparent) from legend
na.translate = FALSE,
guide = if (options[["pathPlotsLegendColor"]]) ggplot2::guide_legend(
title = NULL
) else NULL
)

if (options[["pathPlotsLegend"]]) {
if (options[["pathPlotsLegendLabels"]]) {
nodeLabelUnique <- unique(nodeLabels)
nodeLabelUniqueSorted <- sort(nodeLabelUnique, index.return = TRUE)
# Add legend for label abbreviations by manually overiding dummy alpha variable
Expand Down
25 changes: 18 additions & 7 deletions inst/qml/ClassicProcess.qml
Original file line number Diff line number Diff line change
Expand Up @@ -474,20 +474,14 @@ Form
Group
{
title: qsTr("Path Plots")
columns: 4
columns: 3

CheckBox
{
name: "statisticalPathPlotsParameterEstimates"
label: qsTr("Parameter estimates")
}

CheckBox
{
name: "pathPlotsLegend"
label: qsTr("Legend")
}

IntegerField
{
name: "pathPlotsLabelLength"
Expand All @@ -510,6 +504,23 @@ Form
label: ""
}
}

Group
{
title: qsTr("Legend")
columns: 2

CheckBox
{
name: "pathPlotsLegendLabels"
label: qsTr("Labels")
}
CheckBox
{
name: "pathPlotsLegendColor"
label: qsTr("Color")
}
}
}

}
Expand Down

0 comments on commit 9fdc197

Please sign in to comment.