Skip to content

Commit b38c574

Browse files
committed
reverse accumulation line and fix the count variabel error
1 parent 1b03c32 commit b38c574

File tree

2 files changed

+76
-65
lines changed

2 files changed

+76
-65
lines changed

R/descriptives.R

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
DescriptivesInternal <- function(jaspResults, dataset, options) {
1919

20-
# sink(file="~/Downloads/log.txt")
21-
# on.exit(sink(NULL))
22-
2320
variables <- unlist(options[["variables"]])
2421
variableTypes <- options[["variables.types"]]
2522

@@ -2429,13 +2426,11 @@ DescriptivesInternal <- function(jaspResults, dataset, options) {
24292426
# Normalize input: either a vector OR a 2-col data.frame (category, COUNT)
24302427
if (is.data.frame(column) && ncol(column) == 2) {
24312428
tb <- data.frame(level = column[[1]], Freq = as.numeric(as.character(column[[2]])))
2432-
24332429
} else {
24342430
tab <- table(column, useNA = "no")
24352431
tb <- data.frame(level = names(tab), Freq = as.numeric(tab))
24362432
}
24372433

2438-
24392434
# Order & cumulative %
24402435
tb <- tb[order(tb$Freq, decreasing = TRUE), , drop = FALSE]
24412436
rownames(tb) <- NULL
@@ -2459,24 +2454,26 @@ DescriptivesInternal <- function(jaspResults, dataset, options) {
24592454
# After you build tb (already sorted by Freq desc):
24602455
tb$level <- factor(tb$level, levels = tb$level) # lock global order
24612456

2462-
if (shift) {
2463-
yLabel <- gettextf("Percentage (%%)")
2464-
} else {
2465-
yLabel <- gettext("Counts")
2466-
}
2467-
2468-
# Bars: don't use reorder() anymore
2469-
yBar <- if (shift) tb$Freq / tot * 100 else tb$Freq
2457+
yLabel <- gettext("Counts")
2458+
yBar <- tb$Freq
24702459
p <- ggplot2::ggplot(tb, ggplot2::aes(x = level, y = yBar)) +
24712460
ggplot2::geom_col(fill = "grey", col = "black", width = 0.9) +
24722461
ggplot2::xlab(variable) +
24732462
ggplot2::ylab(yLabel) +
24742463
ggplot2::scale_x_discrete(limits = levels(tb$level), drop = FALSE)
24752464

2476-
# Line: use the same x
2477-
yLine <- if (shift) cumP else tb$cums / scaleRight
2465+
# Line: cumulative counts when shifted, otherwise the old scaled % line
2466+
yLine <- if (shift) cumC else tb$cums / scaleRight
24782467
dfL <- data.frame(level = tb$level, y = yLine)
24792468

2469+
# left-axis breaks
2470+
yBreaksLeft <- if (shift) {
2471+
br <- jaspGraphs::getPrettyAxisBreaks(c(0, tot))
2472+
sort(unique(c(br, tot))) # make sure tot is included as a tick
2473+
} else {
2474+
yBreaks
2475+
}
2476+
24802477
p <- p +
24812478
ggplot2::geom_line(
24822479
data = dfL,
@@ -2492,12 +2489,12 @@ DescriptivesInternal <- function(jaspResults, dataset, options) {
24922489
) +
24932490
ggplot2::scale_y_continuous(
24942491
name = yLabel,
2495-
breaks = if (shift) seq(0, 100, 20) else yBreaks,
2496-
limits = if (shift) c(0, 100) else range(yBreaks),
2492+
breaks = yBreaksLeft,
2493+
limits = if (shift) c(0, tot) else range(yBreaksLeft),
24972494
sec.axis = ggplot2::sec_axis(
2498-
transform = if (shift) ~ . * tot / 100 else ~ . * scaleRight,
2499-
name = if (shift) gettext("Counts") else gettextf("Percentage (%%)"),
2500-
breaks = if (shift) cntBreaks else seq(0, 100, 20)
2495+
transform = if (shift) ~ . * 100 / tot else ~ . * scaleRight,
2496+
name = gettextf("Percentage (%%)"),
2497+
breaks = seq(0, 100, 20)
25012498
)
25022499
) +
25032500
jaspGraphs::geom_rangeframe(sides = "rbl") +
@@ -2522,7 +2519,7 @@ DescriptivesInternal <- function(jaspResults, dataset, options) {
25222519
# y height in *left-axis* units
25232520
# - shifted: left axis is %, so use target directly
25242521
# - normal : left axis is counts; map % -> left via scaleRight
2525-
yGuideLeft <- if (shift) target else perc * max(yBreaks)
2522+
yGuideLeft <- if (shift) perc * tot else perc * max(yBreaks)
25262523

25272524
# horizontal endpoint on the side where % axis lives
25282525
xEnd <- if (shift) 0.5 else length(levels(tb$level)) + 0.5
@@ -2563,7 +2560,6 @@ DescriptivesInternal <- function(jaspResults, dataset, options) {
25632560

25642561

25652562
}
2566-
25672563
.descriptivesDensityPlots <- function(container, dataset, variables, options) {
25682564
# we are not ready to plot
25692565
if (length(variables) == 0)

renv.lock

Lines changed: 58 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Repositories": [
55
{
66
"Name": "CRAN",
7-
"URL": "https://cloud.r-project.org"
7+
"URL": "https://cran.rstudio.com"
88
}
99
]
1010
},
@@ -2448,38 +2448,6 @@
24482448
"Maintainer": "Teun van den Brand <tahvdbrand@gmail.com>",
24492449
"Repository": "RSPM"
24502450
},
2451-
"gghalves": {
2452-
"Package": "gghalves",
2453-
"Version": "0.1.4",
2454-
"Source": "Repository",
2455-
"Title": "Compose Half-Half Plots Using Your Favourite Geoms",
2456-
"Authors@R": "person(\"Frederik\", \"Tiedemann\", email = \"fj.tiedemann@googlemail.com\", role = c(\"aut\", \"cre\"))",
2457-
"Description": "A 'ggplot2' extension for easy plotting of half-half geom combinations. Think half boxplot and half jitterplot, or half violinplot and half dotplot.",
2458-
"URL": "https://github.com/erocoar/gghalves",
2459-
"License": "MIT + file LICENSE",
2460-
"Encoding": "UTF-8",
2461-
"Depends": [
2462-
"ggplot2 (>= 3.3.6)",
2463-
"R (>= 3.3.0)"
2464-
],
2465-
"Imports": [
2466-
"grid",
2467-
"gtable",
2468-
"grDevices"
2469-
],
2470-
"RoxygenNote": "7.2.0",
2471-
"Suggests": [
2472-
"knitr",
2473-
"rmarkdown",
2474-
"dplyr"
2475-
],
2476-
"Collate": "'utilities.R' 'geom_half_dotplot.R' 'geom_half_boxplot.R' 'geom_half_point.R' 'geom_half_point_panel.R' 'geom_half_violin.R' 'stat-half-bindot.R' 'stat-half-point.R' 'stat-half-ydensity.R' 'ggproto-classes.R'",
2477-
"VignetteBuilder": "knitr",
2478-
"NeedsCompilation": "no",
2479-
"Author": "Frederik Tiedemann [aut, cre]",
2480-
"Maintainer": "Frederik Tiedemann <fj.tiedemann@googlemail.com>",
2481-
"Repository": "CRAN"
2482-
},
24832451
"ggplot2": {
24842452
"Package": "ggplot2",
24852453
"Version": "4.0.1",
@@ -3322,41 +3290,75 @@
33223290
"Package": "jaspBase",
33233291
"Version": "0.20.4",
33243292
"Source": "GitHub",
3325-
"Requirements": [
3293+
"Type": "Package",
3294+
"Title": "JASP Base",
3295+
"Author": "JASP Team",
3296+
"Maintainer": "Bruno Boutin <B.Boutin@uva.nl>",
3297+
"Description": "Package contains the JASP Bayesian and Frequentist analyses. See <https://jasp-stats.org> for more details.",
3298+
"License": "GPL2+",
3299+
"Imports": [
33263300
"cli",
33273301
"codetools",
3302+
"compiler",
33283303
"ggplot2",
3304+
"grDevices",
3305+
"grid",
33293306
"gridExtra",
33303307
"gridGraphics",
33313308
"jaspGraphs",
33323309
"jsonlite",
33333310
"lifecycle",
3311+
"methods",
33343312
"officer",
33353313
"pkgbuild",
33363314
"plyr",
33373315
"ragg",
33383316
"R6",
3339-
"Rcpp",
3317+
"Rcpp (>= 0.12.14)",
33403318
"rvg",
33413319
"svglite",
33423320
"systemfonts",
3343-
"withr",
3344-
"testthat"
3321+
"withr"
3322+
],
3323+
"RoxygenNote": "7.3.3",
3324+
"Roxygen": "list(markdown = TRUE)",
3325+
"Encoding": "UTF-8",
3326+
"LinkingTo": [
3327+
"Rcpp"
33453328
],
3329+
"RcppModules": "jaspResults",
3330+
"NeedsCompilation": "yes",
3331+
"Suggests": [
3332+
"testthat (>= 3.0.0)"
3333+
],
3334+
"Config/testthat/edition": "3",
33463335
"RemoteType": "github",
33473336
"RemoteHost": "api.github.com",
33483337
"RemoteUsername": "jasp-stats",
33493338
"RemoteRepo": "jaspBase",
3350-
"RemoteSha": "cf46b53dccdb6c63d4b35f4067d0a8205bbc56dc"
3339+
"RemoteRef": "master",
3340+
"RemoteSha": "cf46b53dccdb6c63d4b35f4067d0a8205bbc56dc",
3341+
"Remotes": "jasp-stats/jaspGraphs"
33513342
},
33523343
"jaspGraphs": {
33533344
"Package": "jaspGraphs",
33543345
"Version": "0.20.0",
33553346
"Source": "GitHub",
3356-
"Requirements": [
3357-
"testthat",
3347+
"Type": "Package",
3348+
"Title": "Custom Graphs for JASP",
3349+
"Author": "Don van den Bergh",
3350+
"Maintainer": "JASP-team <info@jasp-stats.nl>",
3351+
"Description": "Graph making functions and wrappers for JASP.",
3352+
"License": "GPL",
3353+
"Encoding": "UTF-8",
3354+
"LazyData": "true",
3355+
"RoxygenNote": "7.3.3",
3356+
"Suggests": [
3357+
"testthat"
3358+
],
3359+
"Imports": [
33583360
"cli",
3359-
"ggplot2",
3361+
"ggplot2 (>= 3.0.0)",
33603362
"gridExtra",
33613363
"gtable",
33623364
"htmlwidgets",
@@ -3367,17 +3369,28 @@
33673369
"rlang",
33683370
"scales"
33693371
],
3372+
"Roxygen": "list(markdown = TRUE)",
33703373
"RemoteType": "github",
33713374
"RemoteHost": "api.github.com",
33723375
"RemoteUsername": "jasp-stats",
33733376
"RemoteRepo": "jaspGraphs",
3377+
"RemoteRef": "master",
33743378
"RemoteSha": "266f408db9761292050c1319c01640747bf77a0d"
33753379
},
33763380
"jaspTTests": {
33773381
"Package": "jaspTTests",
33783382
"Version": "0.95.5",
33793383
"Source": "GitHub",
3380-
"Requirements": [
3384+
"Type": "Package",
3385+
"Title": "T-Tests Module for JASP",
3386+
"Date": "2022-10-05",
3387+
"Author": "JASP Team",
3388+
"Website": "jasp-stats.org",
3389+
"Maintainer": "JASP Team <info@jasp-stats.org>",
3390+
"Description": "Evaluate the difference between two means",
3391+
"License": "GPL (>= 2)",
3392+
"Encoding": "UTF-8",
3393+
"Imports": [
33813394
"BayesFactor",
33823395
"car",
33833396
"ggplot2",
@@ -3391,7 +3404,9 @@
33913404
"RemoteHost": "api.github.com",
33923405
"RemoteUsername": "jasp-stats",
33933406
"RemoteRepo": "jaspTTests",
3394-
"RemoteSha": "5f513ecf32ea158b4c11b1aed87dc3aa74226bcb"
3407+
"RemoteRef": "master",
3408+
"RemoteSha": "5f513ecf32ea158b4c11b1aed87dc3aa74226bcb",
3409+
"Remotes": "jasp-stats/jaspBase, jasp-stats/jaspGraphs"
33953410
},
33963411
"jpeg": {
33973412
"Package": "jpeg",

0 commit comments

Comments
 (0)