ggplot_add
library(tidyverse)
layers_wipe <- function(i = NULL) {
structure(
list(index_wipe = i),
class = "layers_wipe"
)
}
ggplot_add.layers_wipe <- function(object, plot, object_name) {
if(is.null(object$index_wipe)){
plot$layers <- list()
}else{
plot$layers[object$index_wipe] <- NULL
}
plot
}
ggplot(cars) +
aes(speed, dist) +
geom_point() +
geom_tile()
last_plot() +
layers_wipe(i = 2)
last_plot() +
layers_wipe()
library(ggiraph)
library(ggplot2)
library(S7)
make_interactive <- function(data = NULL) {
structure(
list(),
class = "make_interactive"
)
}
method(update_ggplot, list(new_S3_class("make_interactive"), class_ggplot)) <-
function(object, plot, ...) {
girafe(plot)
}
ggplot(cars) +
aes(speed, dist) +
ggiraph::geom_point_interactive() +
aes(tooltip = speed) +
make_interactive()
library(tidyverse)
library(ggplot2)
layers_remove <- function(i = NULL) {
structure(
list(index_wipe = i),
class = "layers_remove"
)
}
method(update_ggplot, list(new_S3_class("layers_remove"), class_ggplot)) <-
function(object, plot, ...) {
if(is.null(object$index_wipe)){
plot$layers <- list()
}else{
plot$layers[object$index_wipe] <- NULL
}
plot
}
ggplot(cars) +
aes(speed, dist) +
geom_point() +
geom_tile()
last_plot() +
layers_remove(i = 2)
last_plot() +
layers_remove()
ggplot(cars) +
aes(speed, dist)
last_plot() +
layers_remove()
last_plot()@layers
## $geom_blank
## geom_blank: na.rm = FALSE
## stat_identity: na.rm = FALSE
## position_identity