
Last chance! 50% off unlimited learning
Sale ends in
ggplot
to loon
Create an interactive `loon` widget from a ggplot
object
ggplot2loon(
ggObj,
activeGeomLayers = integer(0),
ggGuides = FALSE,
...,
parent = NULL,
pack = TRUE,
tkLabels = NULL,
exteriorLabelProportion = 1/5,
canvasHeight = 700,
canvasWidth = 850
)
a ggplot
or ggmatrix
object
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)
logical (default FALSE
) to determine whether to draw a ggplot background or not.
named arguments to modify loon plot states
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.
logical (or NULL
) to indicate whether the plot(s) are to be wrapped with
exterior labels (title, subtitle, xlabel or ylabel) using tk.grid()
.
If NULL
(default), then exterior labels appear only for multiple facets.
If TRUE
exterior labels appear regardless; if FALSE
no exterior labels appear.
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
a loon
single or compound widget
# NOT RUN {
if(interactive()) {
p <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
g <- ggplot2loon(p)
# tkLabels
p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg,
colour = factor(gear))) + facet_wrap(~am)
g1 <- ggplot2loon(p)
g2 <- ggplot2loon(p, tkLabels = FALSE)
}
# }
# NOT RUN {
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)
# We can select the first geom_point layer to be
# the active layer as in
suppressWarnings(
lp_scatterplots_active1 <- ggplot2loon(scatterplots,
activeGeomLayers = 1,
linkingGroup = "test")
)
# Here the grey points are linked (not the coloured ones)
# We can select the second geom_point layer to be
# the active layer as in
lp_scatterplots_active2 <- ggplot2loon(scatterplots, activeGeomLayers = 2)
# Here the colour points are linked
# We can also select the both geom_point layers to be
# the active layer as in
suppressWarnings(
lp_scatterplots_active12 <- ggplot2loon(scatterplots, activeGeomLayers = c(1,2))
)
# Here the colour points and grey points are both linked
########### ggmatrix to loon ###########
pm <- GGally::ggpairs(iris, column = 1:4, ggplot2::aes(colour=Species))
lg <- ggplot2loon(pm)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab