ggplot2loon {loon.ggplot} | R Documentation |
ggplot
to loon
Description
Create an interactive 'loon' widget from a ggplot
object
Usage
ggplot2loon(
ggObj,
...,
activeGeomLayers = integer(0),
layerId = NULL,
scaleToFun = NULL,
ggGuides = FALSE,
parent = NULL,
pack = TRUE,
exteriorLabelProportion = 1/5,
canvasHeight = 700,
canvasWidth = 850,
tkLabels = NULL
)
Arguments
ggObj |
a |
... |
named arguments to modify loon plot states |
activeGeomLayers |
to determine which geom layer is active. Only |
layerId |
numerical; which layer to scale to |
scaleToFun |
scale to function. See |
ggGuides |
logical (default |
parent |
parent widget path (Tk toplevel) |
pack |
logical (default |
exteriorLabelProportion |
space assigned to the vertical height/horizontal width of each exterior label
expressed as a proportion of a single plot's height/width. Default is 0.2.
This is translated to a row/column span = 1 / exteriorLabelProportion for the plot size in
|
canvasHeight |
the height of canvas |
canvasWidth |
the width of canvas |
tkLabels |
Deprecated: logical (or |
Value
a loon
single widget or a compound object
Examples
if(interactive()) {
p <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
g <- ggplot2loon(p)
p1 <- ggplot(mtcars) +
geom_point(aes(x = wt, y = mpg,
colour = factor(gear))) +
facet_wrap(~am)
g1 <- ggplot2loon(p1)
df <- data.frame(
x = rnorm(120, c(0, 2, 4)),
y = rnorm(120, c(1, 2, 1)),
z = letters[1:3]
)
df2 <- dplyr::select(df, -z)
scatterplots <- ggplot(df, aes(x, y)) +
geom_point(data = df2, colour = "grey70") +
geom_point(aes(colour = z)) +
facet_wrap(~z)
# The first point layer is set as the model layer
suppressWarnings(
lp_scatterplots_active1 <- ggplot2loon(scatterplots,
activeGeomLayers = 1,
linkingGroup = "test")
)
# Here, the gray points are interactive (not the colourful ones)
# The second point layer is set as the model layer
lp_scatterplots_active2 <- ggplot2loon(scatterplots,
activeGeomLayers = 2)
# Here, the colourful points are interactive
# Both point layers could be interactive
suppressWarnings(
lp_scatterplots_active12 <- ggplot2loon(scatterplots,
activeGeomLayers = c(1,2))
)
# Here, all points are interactive
########### ggmatrix to loon ###########
if(requireNamespace("GGally")) {
pm <- GGally::ggpairs(iris, column = 1:4,
ggplot2::aes(colour=Species))
lg <- ggplot2loon(pm)
}
########### patchwork to loon ###########
if(requireNamespace("patchwork")) {
p1 <- ggplot(mtcars) +
geom_point(aes(mpg, disp))
p2 <- ggplot(mtcars) +
geom_boxplot(aes(gear, disp, group = gear))
# place two plots side by side
patchwork <- p1 + p2
ggplot2loon(patchwork)
# See vignette `ggplots --> loon plots` for more details
}
}