Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
Package: jaspGraphs
Type: Package
Title: Custom Graphs for JASP
Version: 0.19.0
Version: 0.19.0.9000
Author: Don van den Bergh
Maintainer: JASP-team <info@jasp-stats.nl>
Description: Graph making functions and wrappers for JASP.
License: GPL
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Suggests: testthat
Imports:
ggplot2 (>= 3.0.0),
Expand All @@ -20,5 +19,6 @@ Imports:
RColorBrewer,
rlang,
scales,
viridisLite
viridisLite,
patchwork
Roxygen: list(markdown = TRUE)
25 changes: 25 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
# Generated by roxygen2: do not edit by hand

S3method("$",Enum)
S3method("[[",jaspGraphsPlot)
S3method("[[<-",jaspGraphsPlot)
S3method(getAxisBreaks,gg)
S3method(getAxisBreaks,ggplot)
S3method(getAxisBreaks,ggplot_built)
S3method(getAxisBreaks,list)
S3method(getAxisInfo,ScaleContinuousPosition)
S3method(getAxisInfo,ScaleDiscretePosition)
S3method(getPlotEditingOptions,"function")
S3method(getPlotEditingOptions,default)
S3method(getPlotEditingOptions,gg)
S3method(getPlotEditingOptions,ggplot)
S3method(getPlotEditingOptions,ggplot_built)
S3method(getPlotEditingOptions,jaspGraphsPlot)
S3method(getPlotEditingOptions,qgraph)
S3method(getPrettyAxisBreaks,character)
S3method(getPrettyAxisBreaks,default)
S3method(getPrettyAxisBreaks,factor)
S3method(getPrettyAxisBreaks,numeric)
S3method(ggMatrixPlot,default)
S3method(ggMatrixPlot,list)
S3method(ggMatrixPlot,matrix)
S3method(internalUpdateAxis,ScaleContinuousPosition)
S3method(internalUpdateAxis,ScaleDiscretePosition)
S3method(length,jaspGraphsPlot)
S3method(makeLabels,default)
S3method(makeLabels,list)
S3method(names,jaspGraphsPlot)
S3method(needsParsing,character)
S3method(needsParsing,data.frame)
Expand All @@ -24,7 +38,11 @@ S3method(plot,jaspGraphs)
S3method(plot,jaspGraphsPlot)
S3method(print,jaspGraphs)
S3method(print,jaspGraphsPlot)
export(.densityArgs)
export(.graphOptions)
export(.histogramArgs)
export(.marginalArgs)
export(.rugArgs)
export(GeomAbline2)
export(GeomAlignedText)
export(GeomRangeFrame)
Expand Down Expand Up @@ -53,7 +71,11 @@ export(ggMatrixPlot)
export(graphOptions)
export(hypothesis2BFtxt)
export(is.jaspGraphsPlot)
export(jaspBivariate)
export(jaspBivariateWithMargins)
export(jaspHistogram)
export(jaspMarginal)
export(jaspMatrixPlot)
export(needsParsing)
export(parseThis)
export(plotEditing)
Expand All @@ -71,6 +93,8 @@ export(themeApaRaw)
export(themeJasp)
export(themeJaspRaw)
export(themePubrRaw)
importFrom(R6,R6Class)
importFrom(RColorBrewer,brewer.pal)
importFrom(ggplot2,.pt)
importFrom(ggplot2,ScaleContinuousPosition)
importFrom(ggplot2,aes)
Expand Down Expand Up @@ -120,3 +144,4 @@ importFrom(gtable,gtable_add_padding)
importFrom(gtable,gtable_add_rows)
importFrom(rlang,.data)
importFrom(scales,censor)
importFrom(viridisLite,viridis)
60 changes: 48 additions & 12 deletions R/JASPScatterPlot.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' @importFrom ggplot2 geom_smooth theme_void geom_ribbon
#' @importFrom rlang .data

#' @title Create a scatter plot with density
#' @title DEPRECATED, use [jaspBivariateWithMargins] instead. Create a scatter plot with density
#'
#' @param x x variable.
#' @param y y variable.
Expand All @@ -19,6 +19,8 @@
#' @param showLegend Should the legend be shown?
#' @param legendTitle A string for the title of the legend. \code{NULL} implies the legend is not shown.
#' @param emulateGgMarginal Should the result be as similar as possible to \code{\link[ggExtra]{ggMarginal}}? Overwrites other parameters.
#' @param plotComposer, String, should "gridExtra" or "patchwork" be used for combining plots?
#' @param legendPosition where should the legend position be placed? "topRightPatch",
#' @param ... passed to \code{\link{themeJaspRaw}}.
#'
#' @details The only change added when \code{emulateGgMarginal = TRUE} is that \code{ggplot2::theme(plot.margin = unit(c(0, 0, 0.25, 0.25), "cm"))}
Expand All @@ -37,8 +39,16 @@ JASPScatterPlot <- function(x, y, group = NULL, xName = NULL, yName = NULL,
showLegend = !is.null(group),
legendTitle = NULL,
emulateGgMarginal = FALSE,
plotComposer = c("gridExtra", "patchwork"),
legendPosition = "topRightPatch",
...) {

lifecycle::deprecate_warn(
"0.19.0.9000",
"JASPScatterPlot()",
"jaspBivariateWithMargins()"
)

# TODO: make actual error messages
stopifnot(
is.numeric(x),
Expand All @@ -53,6 +63,7 @@ JASPScatterPlot <- function(x, y, group = NULL, xName = NULL, yName = NULL,
)
plotAbove <- match.arg(plotAbove)
plotRight <- match.arg(plotRight)
plotComposer <- match.arg(plotComposer)

# can't make a legend without group
showLegend <- showLegend && !is.null(group)
Expand All @@ -76,7 +87,7 @@ JASPScatterPlot <- function(x, y, group = NULL, xName = NULL, yName = NULL,

dots <- list(...)
if (showLegend)
dots <- setDefaults(dots, legend.position = "right")
dots <- setDefaults(dots, legend.position = if (identical(legendPosition, "topRightPatch")) "right" else legendPosition)

mainPlot <- ggplot(df, mapping) +
geom_point() +
Expand All @@ -99,16 +110,41 @@ JASPScatterPlot <- function(x, y, group = NULL, xName = NULL, yName = NULL,
topPlot <- JASPScatterSubPlot(x, group, plotAbove, x.range, colorAreaUnderDensity, alphaAreaUnderDensity)
rightPlot <- JASPScatterSubPlot(y, group, plotRight, y.range, colorAreaUnderDensity, alphaAreaUnderDensity, flip = TRUE)

plotList <- list(mainPlot = mainPlot, topPlot = topPlot, rightPlot = rightPlot)
plotList <- plotList[lengths(plotList) > 0L]
if (plotComposer == "patchwork") {

plot <- jaspGraphsPlot$new(
subplots = plotList,
plotFunction = reDrawAlignedPlot,
size = 5,
showLegend = showLegend
)
return(plot)
topRightPatch <- if (is.null(topPlot)) {
NULL
} else if (identical(legendPosition, "topRightPatch")) {
patchwork::guide_area()
} else {
patchwork::plot_spacer()
}
noLegend <- theme(legend.position = "none")
extraLegend <- if (identical(legendPosition, "topRightPatch")) NULL else theme(legend.position = legendPosition)

plot <-
(topPlot + noLegend) + topRightPatch +
mainPlot + (rightPlot + noLegend) +
patchwork::plot_layout(
widths = c(1, 1 / 5),
heights = c(1 / 5, 1),
guides = "collect"
) & extraLegend
return(plot)

} else {

plotList <- list(mainPlot = mainPlot, topPlot = topPlot, rightPlot = rightPlot)
plotList <- plotList[lengths(plotList) > 0L]

plot <- jaspGraphsPlot$new(
subplots = plotList,
plotFunction = reDrawAlignedPlot,
size = 5,
showLegend = showLegend
)
return(plot)
}
}

JASPScatterSubPlot <- function(x, group = NULL, type = c("density", "histogram", "none"), range,
Expand All @@ -129,7 +165,7 @@ JASPScatterSubPlot <- function(x, group = NULL, type = c("density", "histogram",
foo <- function(x, ...) as.data.frame(stats::density(x, from = range[1L], to = range[2L])[c("x", "y")])
geom <- geom_line(linewidth = 0.5, show.legend = FALSE)
geom2 <- if (colorAreaUnderDensity) {
geom_ribbon(aes(ymin = 0, ymax = .data$y), alpha = alpha)
geom_ribbon(aes(ymin = 0, ymax = .data$y), alpha = alpha, show.legend = FALSE)
} else {
NULL
}
Expand Down
3 changes: 3 additions & 0 deletions R/JASPgraphsPlot.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#' @importFrom ggplot2 is.ggplot

# silences a note in the R CMD Check but is not strictly necessary
#'@importFrom R6 R6Class

jaspGraphsPlot <- R6::R6Class(
classname = "jaspGraphsPlot",
public = list(
Expand Down
4 changes: 4 additions & 0 deletions R/colorPalettes.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

#'@importFrom ggplot2 continuous_scale discrete_scale

# these two silence a note in the R CMD Check but are not strictly necessary
#'@importFrom viridisLite viridis
#'@importFrom RColorBrewer brewer.pal

jaspGraphs_data <- list2env(list(
# discrete color scales
colorblind = list(colors = RColorBrewer::brewer.pal(8L, "Dark2")),
Expand Down
5 changes: 3 additions & 2 deletions R/customGeoms.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#'@importFrom ggplot2 aes

setDefaults <- function(lst, ...) {

Expand All @@ -23,7 +24,7 @@ setDefaults <- function(lst, ...) {
jaspGeomPoint <- ggplot2::ggproto(
`_class` = "jaspGeomPoint",
`_inherit` = ggplot2::GeomPoint,
default_aes = aes(size = 3, shape = 21, colour = "black", fill = "grey", alpha = NA, stroke = 0.5)
default_aes = ggplot2::aes(size = 3, shape = 21, colour = "black", fill = "grey", alpha = NA, stroke = 0.5)
)

#' @title Custom geoms
Expand Down Expand Up @@ -51,7 +52,7 @@ geom_point <- function(mapping = NULL, data = NULL, stat = "identity", position
jaspGeomLine <- ggplot2::ggproto(
`_class` = "jaspGeomLine",
`_inherit` = ggplot2::GeomLine,
default_aes = aes(linewidth = 1.00, colour = "black", linetype = 1, alpha = NA)
default_aes = ggplot2::aes(linewidth = 1.00, colour = "black", linetype = 1, alpha = NA)
)

#' @rdname geom_point
Expand Down
1 change: 1 addition & 0 deletions R/enums.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ createEnum <- function(nameValuePairs) {
e
}

#' @exportS3Method "$" Enum
`$.Enum` <- function(x, y) {
out <- NextMethod(x, y)
if (is.null(out)) stop2(sprintf("nonexisting enum type %s!", y))
Expand Down
2 changes: 1 addition & 1 deletion R/geom_rangeframe.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ GeomRangeFrame <- ggplot2::ggproto("GeomRangeFrame", ggplot2::Geom,
}
ggname("geom_rangeframe", gTree(children = do.call("gList", rugs)))
},
default_aes = aes(colour = "black", size = 0.5, linetype = 1, alpha = NA),
default_aes = ggplot2::aes(colour = "black", size = 0.5, linetype = 1, alpha = NA),

draw_key = ggplot2::draw_key_path
)
9 changes: 9 additions & 0 deletions R/ggMatrixPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ makeLabels <- function(label, angle = 0, size = 1, family = graphOptions("family
UseMethod("makeLabels", label)
}

#' @exportS3Method
makeLabels.default <- function(label, angle = 0, size = 1, family = graphOptions("family"),
vjust = "center", hjust = "center", x = .5, y = .5) {

Expand Down Expand Up @@ -70,6 +71,7 @@ makeLabels.default <- function(label, angle = 0, size = 1, family = graphOptions
}
}

#' @exportS3Method
makeLabels.list <- function(label, angle = 0, size = 1, family = graphOptions("family"),
vjust = "center", hjust = "center", x = .5, y = .5) {

Expand Down Expand Up @@ -385,6 +387,13 @@ ggMatrixPlot.default <- function(plotList = NULL, nr = NULL, nc = NULL,
scaleXYlabels = c(.9,.9),
debug = FALSE) {

lifecycle::deprecate_warn(
"0.19.0.9000",
"jaspGraphs::ggMatrixPlot(...)",
"jaspGraphs::jaspMatrixPlot(...)",
details = "jaspMatrixPlot supersedes ggMatrixPlot."
)

removeXYlabels <- match.arg(removeXYlabels)
if (is.null(plotList) && debug) {

Expand Down
Loading