@@ -943,15 +943,15 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
943943 if (! is.finite(baseStep ))
944944 baseStep <- occupiedSpan / 4
945945
946- focusPadding <- max(baseStep , occupiedSpan * 0.08 )
946+ focusPadding <- max(baseStep * 1.5 , occupiedSpan * 0.12 )
947947 focusRange <- c(max(xLimits [1 ], occupiedRange [1 ] - focusPadding ), min(xLimits [2 ], occupiedRange [2 ] + focusPadding ))
948948 if (focusRange [1 ] > = focusRange [2 ])
949949 focusRange <- occupiedRange
950950
951951 focusSpan <- max(diff(focusRange ), 1e-8 )
952952 leftGap <- max(0 , focusRange [1 ] - xLimits [1 ])
953953 rightGap <- max(0 , xLimits [2 ] - focusRange [2 ])
954- compressThreshold <- max(focusSpan * 1.25 , baseStep * 6 )
954+ compressThreshold <- max(focusSpan * 0.6 , baseStep * 3 )
955955 compressedGap <- max(focusSpan * 0.18 , baseStep * 1.5 )
956956 compressLeft <- isTRUE(compress ) && leftGap > compressThreshold
957957 compressRight <- isTRUE(compress ) && rightGap > compressThreshold
@@ -979,12 +979,46 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
979979
980980 centerBreaks <- unique(pretty(focusRange , n = 5 ))
981981 centerBreaks <- centerBreaks [centerBreaks > = focusRange [1 ] & centerBreaks < = focusRange [2 ]]
982- breaksOriginal <- sort(unique(c(
983- if (compressLeft ) xLimits [1 ] else pretty(c(xLimits [1 ], focusRange [1 ]), n = 2 ),
984- centerBreaks ,
985- if (compressRight ) xLimits [2 ] else pretty(c(focusRange [2 ], xLimits [2 ]), n = 2 )
986- )))
987- breaksOriginal <- breaksOriginal [breaksOriginal > = xLimits [1 ] & breaksOriginal < = xLimits [2 ]]
982+
983+ if (compressLeft || compressRight ) {
984+ sideBreaksLeft <- if (compressLeft ) xLimits [1 ] else pretty(c(xLimits [1 ], focusRange [1 ]), n = 2 )
985+ sideBreaksRight <- if (compressRight ) xLimits [2 ] else pretty(c(focusRange [2 ], xLimits [2 ]), n = 2 )
986+ shoulderBreaks <- numeric (0 )
987+ if (compressLeft )
988+ shoulderBreaks <- c(shoulderBreaks , focusRange [1 ])
989+ if (compressRight )
990+ shoulderBreaks <- c(shoulderBreaks , focusRange [2 ])
991+ breaksOriginal <- sort(unique(c(sideBreaksLeft , shoulderBreaks , centerBreaks , sideBreaksRight )))
992+ breaksOriginal <- breaksOriginal [breaksOriginal > = xLimits [1 ] & breaksOriginal < = xLimits [2 ]]
993+
994+ centerLabelBreaks <- centerBreaks [centerBreaks > focusRange [1 ] & centerBreaks < focusRange [2 ]]
995+ if (length(centerLabelBreaks ) < 2 )
996+ centerLabelBreaks <- centerBreaks
997+
998+ if (length(centerLabelBreaks ) > 3 ) {
999+ keepIndices <- unique(round(seq(1 , length(centerLabelBreaks ), length.out = 3 )))
1000+ centerLabelBreaks <- centerLabelBreaks [keepIndices ]
1001+ }
1002+
1003+ visibleBreaks <- centerLabelBreaks
1004+ if (compressLeft )
1005+ visibleBreaks <- c(xLimits [1 ], visibleBreaks )
1006+ if (compressRight )
1007+ visibleBreaks <- c(visibleBreaks , xLimits [2 ])
1008+
1009+ decimals <- max(3 , .qcCapabilityAxisLabelDecimals(visibleBreaks ))
1010+ xLabels <- rep(" " , length(breaksOriginal ))
1011+ visibleIndices <- which(breaksOriginal %in% visibleBreaks )
1012+ xLabels [visibleIndices ] <- .qcFormatCapabilityAxisLabelsFixed(breaksOriginal [visibleIndices ], decimals )
1013+ } else {
1014+ breaksOriginal <- sort(unique(c(
1015+ pretty(c(xLimits [1 ], focusRange [1 ]), n = 2 ),
1016+ centerBreaks ,
1017+ pretty(c(focusRange [2 ], xLimits [2 ]), n = 2 )
1018+ )))
1019+ breaksOriginal <- breaksOriginal [breaksOriginal > = xLimits [1 ] & breaksOriginal < = xLimits [2 ]]
1020+ xLabels <- .qcFormatCapabilityAxisLabels(breaksOriginal )
1021+ }
9881022
9891023 displayLimits <- range(transform_x(xLimits ))
9901024 breakMarkers <- c()
@@ -996,7 +1030,7 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
9961030 list (
9971031 transform = transform_x ,
9981032 xBreaks = transform_x(breaksOriginal ),
999- xLabels = .qcFormatCapabilityAxisLabels( breaksOriginal ) ,
1033+ xLabels = xLabels ,
10001034 xLimits = displayLimits ,
10011035 breakMarkers = breakMarkers ,
10021036 curveRange = if (compressLeft || compressRight ) focusRange else xLimits ,
@@ -1270,20 +1304,33 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
12701304 }
12711305
12721306 if (axisConfig $ hasBreak ) {
1273- slashHeight <- yUpper * 0.05
1274- slashWidth <- diff(axisConfig $ xLimits ) * 0.01
1275- slashGap <- slashWidth * 0.75
1307+ slashHeight <- yUpper * 0.04
1308+ slashDepth <- yUpper * 0.02
1309+ slashWidth <- diff(axisConfig $ xLimits ) * 0.012
1310+ slashGap <- slashWidth * 0.9
1311+ axisCutDf <- do.call(rbind , lapply(axisConfig $ breakMarkers , function (marker ) {
1312+ data.frame (
1313+ x = marker - (slashGap + slashWidth ) * 1.4 ,
1314+ xend = marker + (slashGap + slashWidth ) * 1.4 ,
1315+ y = 0 ,
1316+ yend = 0
1317+ )
1318+ }))
12761319 breakMarkerDf <- do.call(rbind , lapply(axisConfig $ breakMarkers , function (marker ) {
12771320 data.frame (
12781321 x = c(marker - slashGap - slashWidth / 2 , marker + slashGap - slashWidth / 2 ),
12791322 xend = c(marker - slashGap + slashWidth / 2 , marker + slashGap + slashWidth / 2 ),
1280- y = c(0.01 * yUpper , 0.01 * yUpper ),
1323+ y = c(- slashDepth , - slashDepth ),
12811324 yend = c(slashHeight , slashHeight )
12821325 )
12831326 }))
1284- p <- p + ggplot2 :: geom_segment(data = breakMarkerDf ,
1327+ p <- p +
1328+ ggplot2 :: geom_segment(data = axisCutDf ,
1329+ mapping = ggplot2 :: aes(x = x , xend = xend , y = y , yend = yend ),
1330+ inherit.aes = FALSE , linewidth = 2.2 , color = " white" ) +
1331+ ggplot2 :: geom_segment(data = breakMarkerDf ,
12851332 mapping = ggplot2 :: aes(x = x , xend = xend , y = y , yend = yend ),
1286- inherit.aes = FALSE , linewidth = 0.7 )
1333+ inherit.aes = FALSE , linewidth = 1.1 , color = " black " )
12871334 }
12881335
12891336 if (length(legendColors ) > 0 ) {
@@ -1293,6 +1340,7 @@ processCapabilityStudies <- function(jaspResults, dataset, options) {
12931340 if (nStages > 1 )
12941341 p <- p + ggplot2 :: ggtitle(stage ) + ggplot2 :: theme(plot.title = ggplot2 :: element_text(face = " bold" ))
12951342 p <- p + jaspGraphs :: geom_rangeframe() +
1343+ ggplot2 :: coord_cartesian(clip = " off" ) +
12961344 jaspGraphs :: themeJaspRaw() +
12971345 ggplot2 :: theme(axis.text.y = ggplot2 :: element_blank(), axis.ticks.y = ggplot2 :: element_blank(),
12981346 legend.position = " right" , plot.margin = ggplot2 :: margin(12 , 18 , 8 , 8 ))
0 commit comments