remove_figure: Remove a figure

Description Usage Arguments Examples

View source: R/remove.R

Description

Remove a figure from the plot.

Usage

1
remove_figure(g, index)

Arguments

g

An object of class g2r or g2Proxy as returned by g2() or g2_proxy().

index

Index of figure to remove. Either the numeric index of figure (layer number in order it was added to the visualisation), or the id of the figure as set by config() (see examples).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
g <- g2(mtcars, asp(qsec, wt)) %>%
  fig_point(config(id = "myPoints")) %>%
  fig_point(asp(y = drat))

# all figures
g

# remove figure
remove_figure(g, "myPoints")

library(shiny)

df <- data.frame(
  x = 1:100,
  y = runif(100),
  z = runif(100)
)

ui <- fluidPage(
  g2Output("plot"),
  actionButton("rm", "Randomly remove a figure")
)

server <- function(input, output) {
  output$plot <- renderG2({
    g2(df, asp(x, y)) %>%
      fig_point() %>%
      fig_line(asp(y = z))
  })

  observeEvent(input$rm, {
    g2_proxy("plot") %>%
      remove_figure(sample(1:2, 1))
  })
}

if (interactive()) {
  shinyApp(ui, server)
}

devOpifex/g2r documentation built on Jan. 16, 2022, 12:36 a.m.