I have some data like this:
df <- tibble(
key = c("v1", "v1", "v1", "v1", "v2", "v2", "v2", "v2", "v3"),
values = c(1, 2, 4, 2, 5, 8, 3, 1, 0)
)
and create a histogram of each value:
plot <- df %>%
ggplot(aes(x = values)) +
geom_histogram(aes(y = ..count..)) +
facet_wrap(~key, scales = "free", nrow = 1)
These values represent occurences of a specific observation. What I want is to replace a plot with some default text like "No data", if the histogram shows only one bar at x = 0, like it is the case in the third subplot. Is there a way to achieve this?




