Skip to content

Commit

Permalink
Fix density plots (#352)
Browse files Browse the repository at this point in the history
* fix density plots

* embarassing bugfix
  • Loading branch information
vandenman authored Mar 6, 2025
1 parent 67cde7a commit 85c0c4e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
24 changes: 17 additions & 7 deletions R/descriptives.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ DescriptivesInternal <- function(jaspResults, dataset, options) {

if (is.null(dataset)) {

preloadData <- FALSE
temp <- .descriptivesReadData(options, variables, splitName)
dataset <- temp[["dataset"]]
dataset.factors <- temp[["dataset.factors"]]

} else {

preloadData <- TRUE
dataset.factors <- dataset
for (var in variables)
dataset[[var]] <- as.numeric(dataset[[var]])
Expand Down Expand Up @@ -342,7 +344,7 @@ DescriptivesInternal <- function(jaspResults, dataset, options) {
jaspResults[["densityPlot"]]$position <- 17
}

.descriptivesDensityPlots(jaspResults[["densityPlot"]], dataset.factors, variables, options)
.descriptivesDensityPlots(jaspResults[["densityPlot"]], dataset.factors, variables, options, preloadData)
}

# Likert plots
Expand Down Expand Up @@ -2471,22 +2473,30 @@ DescriptivesInternal <- function(jaspResults, dataset, options) {
ggplot2::theme(plot.margin = ggplot2::margin(5))
}

.descriptivesDensityPlots <- function(container, dataset, variables, options) {
.descriptivesDensityPlots <- function(container, dataset, variables, options,
preloadData) {
# we are not ready to plot
if (length(variables) == 0)
return()

if (options[["densityPlotSeparate"]] != "") {
separator <- as.factor(dataset[[options[["densityPlotSeparate"]]]])
if (preloadData)
separator <- as.factor(dataset[[options[["densityPlotSeparate"]]]])
else {
separator <- .readDataSetToEnd(columns.as.factor = options[["densityPlotSeparate"]])
separator <- separator[, , drop = TRUE]
}
}

for (i in seq_along(variables)) {
# if (!is.double(dataset[[i]])) next

variableName <- variables[[i]]
# variable <- .readDataSetToEnd(columns = variableName)
# variable <- variable[, , drop = TRUE]
variable <- dataset[[variableName]]
if (preloadData) {
variable <- dataset[[variableName]]
} else {
variable <- .readDataSetToEnd(columns = variableName)
variable <- variable[, , drop = TRUE]
}
variableType <- options[["variables.types"]][[i]]
data <- if (options[["densityPlotSeparate"]] != "") {
data.frame(variable, separator)
Expand Down
1 change: 1 addition & 0 deletions jaspDescriptives.Rproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Version: 1.0
ProjectId: e85ae8ed-5382-4e6c-ac95-b9ea9816d49c

RestoreWorkspace: Default
SaveWorkspace: Default
Expand Down

0 comments on commit 85c0c4e

Please sign in to comment.