Create an interactive `loon` widget from a ggplot
object
ggplot2loon(
ggObj,
...,
activeGeomLayers = integer(0),
layerId = NULL,
scaleToFun = NULL,
ggGuides = FALSE,
parent = NULL,
pack = TRUE,
exteriorLabelProportion = 1/5,
canvasHeight = 700,
canvasWidth = 850,
tkLabels = NULL
)
a ggplot
or ggmatrix
object
named arguments to modify loon plot states
to determine which geom layer is active. Only geom_point()
and geom_histogram()
can be set as active geom layer(s) so far.
(Notice, more than one geom_point()
layers can be set as active layers,
but only one geom_histogram()
can be set as an active geom layer)
numerical; which layer to scale to
scale to function. See zoom
.
logical (default FALSE
) to determine whether to draw a ggplot background or not.
parent widget path (Tk toplevel)
logical (default TRUE
) to pack widgets.
If FALSE
, widgets will be produced but won't be packed and so will not appear in the display.
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
tkgrid()
.
the height of canvas
the width of canvas
Deprecated: logical (or NULL
) to indicate whether the plot(s) are to be wrapped by
exterior labels (title, subtitle, xlabel or ylabel) using tk.grid()
a loon
single widget or a compound object
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)
# \donttest{
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
}
# }
}