View source: R/ggMarginal_Hist2D.R
ggMarginal_Hist2D | R Documentation |
Create a ggplot2 2d histogram plot with marginal histogram plots.
ggMarginal_Hist2D(
data,
x,
y,
size = 5,
after_stat_var = c("ncount", "count", "density", "ndensity"),
hist_scale = c("arithmetic", "log10", "4th-root"),
bins = 30,
binwidths = NULL,
xlab = NULL,
ylab = NULL,
xparams = list(limits = NULL, breaks = waiver(), labels = waiver(), name = waiver(),
oob = scales::squish),
yparams = list(limits = NULL, breaks = waiver(), labels = waiver(), name = waiver(),
oob = scales::squish),
fill_scale = ggplot2::scale_fill_viridis_c(option = "magma", name = ""),
legend.position = c(0.99, 0.99),
legend.justification = c(1, 1),
...,
groupColour = FALSE,
groupFill = FALSE,
showIntermediates = FALSE,
testing = FALSE
)
data |
The data.frame to use for creating the plots. |
x |
The name of the variable along the x axis. |
y |
The name of the variable along the y axis. |
size |
Integer describing the relative size of the marginal plots compared to the main plot. A size of 5 means that the main plot is 5x wider and 5x taller than the marginal plots. |
hist_scale |
- scale for histograms; options = ("arithmetic","log10","4th-root") |
bins |
- number of bins to use (scalar or 2-element vector); default=30 |
binwidths |
- bin widths to use (scalar or 2-element vector); default=NULL |
xlab |
- x-axis title; default=NULL (i.e., use ggplot2 default) |
ylab |
- y-axis title; default=NULL (i.e., use ggplot2 default) |
xparams |
- list of [ggplot2::scale_x_continuous()] parameters; default = list(limits=NULL,breaks=waiver(),labels=waiver(),oob=scales::squish) |
yparams |
- list of [ggplot2::scale_y_continuous()] parameters; default = list(limits=NULL,breaks=waiver(),labels=waiver(),oob=scales::squish) |
fill_scale |
- 2d histogram fill scale; default=ggplot2::scale_fill_viridis_c(option="magma",name="") |
legend.position |
- legend position; default=c(0.99,0.99) |
legend.justification |
- legend justification; default=c(1,1) |
... |
Extra parameters to pass to the marginal plots. Any parameter that
[ggplot2::geom_histogram()] accepts can be used.
For example, |
groupColour |
If |
groupFill |
If |
testing |
- flag (T/F) to include |
stat_var |
- name of statistical variable to plot; options=("count","ncount","density","ndensity") |
If testing
is false, a ggGTbl
object that can be printed using S3 dispatch with print
.
If testing
is TRUE, a list with elements
ggGTbl - an object of class ggGTbl
.
built - a list with elements p2d, px,py corresponding to ggplot2 objects "built" with [ggplot2::ggplot_build()]
The grid
, gtable
, and rlang
packages are required for this
function.
This function and related code are based on the [ggExtra::ggMarginal()] code developed by Dean Attali ("daattali@gmail.com").
library(ggplot2)
ggGTbl = ggMarginal_Hist2D(data=mtcars,x=wt,y=mpg,
hist_scale="arithmetic",
binwidths=c(0.5,7),
xparams=list(limits=c(0, 3),breaks=seq(0, 7,0.5),oob=scales::squish),
yparams=list(limits=c(0,40),breaks=seq(0,40,2),oob=scales::squish),
legend.position=c(0.01,0.99),
legend.justification=c(0,1),
showIntermediates=FALSE);
print(ggGTbl,newpage=TRUE);
gglst = ggMarginal_Hist2D(data=mtcars,x=wt,y=mpg,
hist_scale="arithmetic",
binwidths=c(0.5,7),
xparams=list(limits=c(0, 3),breaks=seq(0, 7,0.5),oob=scales::squish),
yparams=list(limits=c(0,40),breaks=seq(0,40,2),oob=scales::squish),
legend.position=c(0.01,0.99),
legend.justification=c(0,1),
showIntermediates=FALSE,
testing=TRUE);
print(gglst$ggGTbl,newpage=TRUE);
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.