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
}
# }
}
Run the code above in your browser using DataLab