if(interactive()) {
########################## l_plot.default ##########################
# default use as scatterplot
p1 <- with(iris, l_plot(Sepal.Length, Sepal.Width, color=Species,
title = "First plot"))
# The names of the info states that can be
# accessed or set. They can also be given values as
# arguments to l_plot.default()
names(p1)
p1["size"] <- 10
p2 <- with(iris, l_plot(Petal.Length ~ Petal.Width,
linkingGroup="iris_data",
title = "Second plot",
showGuides = FALSE))
p2["showScales"] <- TRUE
# link first plot with the second plot requires
# l_configure to coordinate the synchroniztion
l_configure(p1, linkingGroup = "iris_data", sync = "push")
p1['selected'] <- iris$Species == "versicolor"
p2["glyph"][p1['selected']] <- "cdiamond"
gridExtra::grid.arrange(loonGrob(p1), loonGrob(p2), nrow = 1)
# Layout facets
### facet wrap
p3 <- with(mtcars, l_plot(wt, mpg, by = cyl, layout = "wrap"))
# it is equivalent to
# p3 <- l_plot(mpg~wt, by = ~cyl, layout = "wrap", on = mtcars)
### facet grid
p4 <- l_plot(x = 1:6, y = 1:6,
by = size ~ color,
size = c(rep(50, 2), rep(25, 2), rep(50, 2)),
color = c(rep("red", 3), rep("green", 3)))
# Use with other tk widgets
tt <- tktoplevel()
tktitle(tt) <- "Loon plots with custom layout"
p1 <- l_plot(parent=tt, x=c(1,2,3), y=c(3,2,1))
p2 <- l_plot(parent=tt, x=c(4,3,1), y=c(6,8,4))
tkgrid(p1, row=0, column=0, sticky="nesw")
tkgrid(p2, row=0, column=1, sticky="nesw")
tkgrid.columnconfigure(tt, 0, weight=1)
tkgrid.columnconfigure(tt, 1, weight=1)
tkgrid.rowconfigure(tt, 0, weight=1)
########################## l_plot.decomposed.ts ##########################
decompose <- decompose(co2)
p <- l_plot(decompose, title = "Atmospheric carbon dioxide over Mauna Loa")
# names of plots in the display
names(p)
# names of states associated with the seasonality plot
names(p$seasonal)
# which can be set
p$seasonal['color'] <- "steelblue"
########################## l_plot.stl ##########################
co2_stl <- stl(co2, "per")
p <- l_plot(co2_stl, title = "Atmospheric carbon dioxide over Mauna Loa")
# names of plots in the display
names(p)
# names of states associated with the seasonality plot
names(p$seasonal)
# which can be set
p$seasonal['color'] <- "steelblue"
########################## l_plot.density ##########################
# plot a density estimate
set.seed(314159)
ds <- density(rnorm(1000))
p <- l_plot(ds, title = "density estimate",
xlabel = "x", ylabel = "density",
showScales = TRUE)
########################## l_plot.map ##########################
if (requireNamespace("maps", quietly = TRUE)) {
p <- l_plot(maps::map('world', fill=TRUE, plot=FALSE))
}
}
Run the code above in your browser using DataLab