How do I keep all the legends in plot? Below is an example of scatter plot. It prints only if x > 0.5. But I want to show all the legends.
library(tidyverse)
for (iter in 1:5)
{
# generate 5 random points
tbl <- tibble(x = runif(5),
y = runif(5),
class = c("A", "B", "C", "D", "E"))
# print if x > 0.5
p <- ggplot(data = tbl %>% filter(x > 0.5),
aes(x = x,
y = y,
color = class)) +
geom_point(size = 5) +
scale_fill_manual(labels = c("A", "B", "C", "D", "E"),
values = c("Grey", "Red", "Green", "Blue", "Yellow"),
drop = FALSE) +
theme_bw() +
theme(aspect.ratio = 1) +
xlim(0, 1) +
ylim(0, 1)
ggsave(p,
filename = paste0(iter, ".png"))
}


