Replies: 1 comment
-
Trying this out currently. 😬 Saving unfiltered data in new plot list item plot$unfiltered_data <- plot$unfiltered_data %||% plot$data Then an unfiltering function restores initial data input. plot$data <- plot$unfiltered_data |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm wondering if people had ideas about a reversible in-plot data manipulation filter method. Sometimes, I might like to filter, but then downstream recover the full data (I think).
last_plot() +
data_filter(cyl != 4)
I kind of am inspired by this data_nest/data_unnest(). Which lets you look at unique observations based on a var or sets of vars. My go to would be distinct, if I weren't interested in being able to restore the data. But, I distinct drops a lot of info, while nest collapses it. Not sure that this can actually help answer the filter question.
data_nest <- function(.by) {
structure(list(by_specification = rlang::enquo(.by)),
class = "data_nestvar")
}
ggplot_add.data_nestvar <- function(object, plot, object_name) {
new_data <- tidyr::nest(plot$data,
.by = !! object$by_specification)
plot$data <- new_data
plot
}
data_unnest <- function(cols) {
structure(list(),
class = "data_unnestvar")
}
ggplot_add.data_unnestvar <- function(object, plot, object_name) {
new_data <- tidyr::unnest(plot$data, cols = "data")
plot$data <- new_data
plot
}
library(ggplot2)
diamonds |>
ggplot() +
aes(x = cut) +
geom_bar()
last_plot() +
data_nest(.by = cut)
last_plot() +
data_unnest()
Beta Was this translation helpful? Give feedback.
All reactions