Create a loon widget with ggplot syntax

l_ggplot(data = NULL, mapping = aes(), ..., environment = parent.frame())



Default dataset to use for plot. If not already a data.frame, will be converted to one by fortify(). If not specified, must be supplied in each layer added to the plot.


Default list of aesthetic mappings to use for plot. If not specified, must be supplied in each layer added to the plot.


Other arguments passed on to methods. Not currently used.


DEPRECATED. Used prior to tidy evaluation.


It will return an l_ggplot object with class c("l_ggplot", "gg", "ggplot"). Then print a loon plot automatically.


function l_ggplot() wraps function ggplot() with assigning an additional class "l_ggplot" to the output. The returned object is called an l_ggplot object. To draw a ggplot object, S3 method print.ggplot will be rendered so that a static graphic is displayed. While, for an l_ggplot() object, S3 method print.l_ggplot will be rendered which will return an interactive loon widget.


if(interactive()) {
p <- l_ggplot(mpg, aes(displ, cty)) +
      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

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

# 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)

# 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
         mapping = aes(x = wt, y = hp, z = drat)) +
   geom_point(size = 4) +