stat_filter | R Documentation |
Only keeps values where the aesthetic filter evaluates to TRUE
.
Useful for showing only a subset of the data or to highlight some values, without filtering the data outside.
Inspired by metR::stat_subset()
.
stat_filter(
mapping = NULL,
data = NULL,
geom = "point",
position = "identity",
show.legend = FALSE,
inherit.aes = TRUE,
na.rm = TRUE,
...
)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
The geometric object to use to display the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
na.rm |
remove na values befor applying filter |
... |
Other arguments passed on to
|
ggplot2 layer
filter: expression evalueted against data
require(ggplot2)
p <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
p + stat_filter(aes(filter = mpg > 30), shape = 21, size = 4, stroke = 2, color = "red", fill = NA)
p + geom_text(aes(filter = mpg > 32, label = rownames(mtcars)),
stat = "filter", nudge_y = 0.75)
data <- tidyr::crossing(y = 1:dim(volcano)[2], x = 1:dim(volcano)[1])
data$value <- array(volcano)
ggplot(data, aes(x = x, y = y)) +
geom_contour(aes(z = value)) +
stat_filter(aes(filter = value >= 150 & value <= 160), shape = 3, color = "red")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.