loon.ggplot: loon.ggplot

View source: R/loon_ggplot.R

loon.ggplotR Documentation

loon.ggplot

Description

A bridge between loon widgets and gg objects. It can take either a loon widget, a gg object (ggplot, GGally::ggmatrix) or a l_ggplot object, then create a corresponding gg (or loon) graphics.

Usage

loon.ggplot(x, ...)

## S3 method for class 'gg'
loon.ggplot(x, ...)

## S3 method for class 'loon'
loon.ggplot(x, ...)

## S3 method for class 'zenplot'
loon.ggplot(x, ...)

## S3 method for class 'l_ggplot'
loon.ggplot(x, ...)

Arguments

x

A loon widget, a ggplot object or a l_ggplot object.

...

arguments used in either loon2ggplot() or ggplot2loon()

Value

If the input is a ggplot object, the output would be a loon widget; conversely, if the input is a loon widget, then it returns a ggplot object. If it is a l_ggplot object, loon.ggplot helps to return a loon widget.

See Also

Richer examples are in loon2ggplot, ggplot2loon, l_ggplot

Examples


if(interactive()) {
######### loon --> gg #########
  # loon 3D plot
  l <- with(quakes,
    l_plot3D(long, lat, depth, linkingGroup = "quakes")
  )
  # equivalent to `loon2ggplot(l)`
  g <- loon.ggplot(l)
  g # a ggplot object

######### gg --> loon #########

  # ggplot histogram
  g <- ggplot(iris, mapping = aes(Sepal.Length, fill = Species)) +
    geom_histogram()
  # equivalent to `ggplot2loon(g)`
  l <- loon.ggplot(g)
  l # a loon widget

######### l_ggplot #########
  p <- l_ggplot(mpg, aes(displ, fill = factor(cyl))) +
       geom_histogram()
  class(p)
  # Function `print.l_ggplot` is called automatically
  p
  # Function `loon.ggplot` helps to return a loon widget
  q <- loon.ggplot(p)
  q
}

loon.ggplot documentation built on May 29, 2024, 4:58 a.m.