if(interactive()) {
p <- l_ggplot(mpg, aes(displ, cty)) +
geom_point(
size = 4,
mapping = aes(color = factor(cyl))
)
# p is an `l_ggplot` object, `print.l_ggplot(p)` will be called automatically.
# Then, at printing time, an `l_ggplot` object will be transformed to a `loon` widget
p
if (FALSE) {
# Assign a widget from current path
# suppose the path of `p` is '.l0.ggplot'
q <- l_getFromPath('.l0.ggplot')
# q is a `loon` widget
q
}
# An alternative way to return a real loon widget from `p` (a `l_ggplot` object)
# is to call the function `loon.ggplot()`.
q <- loon.ggplot(p)
q
# pipe more components
p +
facet_grid(rows = vars(drv)) +
linking(linkingGroup = "mpg") +
ggtitle("displ versus cty")
# a linked bar plot
l_hist(mpg$class, linkingGroup = "mpg")
# a 3D object
# press the button key `R` to rotate the plot
l_ggplot(mtcars,
mapping = aes(x = wt, y = hp, z = drat)) +
geom_point(size = 4) +
scale_multi()
}
Run the code above in your browser using DataLab