Create a scatter plot with density

JASPScatterPlot(
  x,
  y,
  group = NULL,
  xName = NULL,
  yName = NULL,
  addSmooth = TRUE,
  addSmoothCI = TRUE,
  smoothCIValue = 0.95,
  forceLinearSmooth = FALSE,
  plotAbove = c("density", "histogram", "none"),
  plotRight = c("density", "histogram", "none"),
  colorAreaUnderDensity = TRUE,
  alphaAreaUnderDensity = 0.5,
  showLegend = !is.null(group),
  legendTitle = NULL,
  emulateGgMarginal = FALSE,
  ...
)

Arguments

x

x variable.

y

y variable.

group

optional grouping variable.

xName

name on x-axis.

yName

name on y-axis.

addSmooth

should a smoothed regression line be drawn?

addSmoothCI

should a confidence interval be added to the smoothed regression line?

smoothCIValue

a numeric in (0, 1) indicating the confidence interval.

forceLinearSmooth

should the regression line be linear?

plotAbove

type of plot above the scatter plot.

plotRight

type of plot right of the scatter plot.

colorAreaUnderDensity

Logical, should the area under the density be colored?

alphaAreaUnderDensity

Real in [0, 1], transparency for area under density.

showLegend

Should the legend be shown?

legendTitle

A string for the title of the legend. NULL implies the legend is not shown.

emulateGgMarginal

Should the result be as similar as possible to ggMarginal? Overwrites other parameters.

...

passed to themeJaspRaw.

Details

The only change added when emulateGgMarginal = TRUE is that ggplot2::theme(plot.margin = unit(c(0, 0, 0.25, 0.25), "cm")) is added to the main plot

Examples

if (FALSE) {

x <- rnorm(100)
y <- rgamma(100, 1, 1)

JASPScatterPlot(x, y, xName = "Normal", yName = expression(gamma))
JASPScatterPlot(x, y, xName = "Normal", yName = expression(gamma), forceLinearSmooth = TRUE)
JASPScatterPlot(x, y, xName = "Normal", yName = expression(gamma), forceLinearSmooth = TRUE,
                smoothCIValue = .99)
JASPScatterPlot(x, y, xName = "Normal", yName = "Gamma", addSmooth = FALSE)
JASPScatterPlot(x, y, xName = "Normal", yName = "Gamma", addSmoothCI = FALSE)

JASPScatterPlot(x, y, xName = "Normal", yName = "Gamma", plotAbove = "histogram")
JASPScatterPlot(x, y, xName = "Normal", yName = "Gamma", plotAbove = "histogram",
                plotRight = "histogram")

JASPScatterPlot(x, y, xName = "Normal", yName = "Gamma", plotAbove = "histogram",
                plotRight = "none")
JASPScatterPlot(x, y, xName = "Normal", yName = "Gamma", plotAbove = "none",
                plotRight = "none")

# we can do the same with a grouping variable
data("mtcars")
JASPScatterPlot(x = mtcars$mpg, y = mtcars$disp, group = mtcars$cyl)
JASPScatterPlot(x = mtcars$mpg, y = mtcars$disp, group = mtcars$cyl, plotAbove = "none")
JASPScatterPlot(x = mtcars$mpg, y = mtcars$disp, group = mtcars$cyl, plotRight = "none")
JASPScatterPlot(x = mtcars$mpg, y = mtcars$disp, group = mtcars$cyl, plotRight = "none",
                plotAbove = "none")

JASPScatterPlot(x = mtcars$mpg, y = mtcars$disp, group = mtcars$cyl, plotAbove = "histogram",
                plotRight = "histogram")

# the color scheme can be changed with the global options:
oldColor <- graphOptions("palette")
graphOptions(palette = "ggplot2")
JASPScatterPlot(x = mtcars$mpg, y = mtcars$disp, group = mtcars$cyl)
graphOptions(palette = "viridis")
JASPScatterPlot(x = mtcars$mpg, y = mtcars$disp, group = mtcars$cyl)
graphOptions(palette = "colorblind3")
JASPScatterPlot(x = mtcars$mpg, y = mtcars$disp, group = mtcars$cyl)
graphOptions(palette = "gray")
JASPScatterPlot(x = mtcars$mpg, y = mtcars$disp, group = mtcars$cyl)
graphOptions(palette = oldColor)

## NOT RUN
# spot the differences (if you find any report them to the package maintainer!)
plot <- JASPScatterPlot(x, y, xName = "Normal", yName = "Gamma", addSmooth = FALSE,
                        emulateGgMarginal = TRUE)
plot
# ggExtra::ggMarginal(plot$subplots[[1]])

}