I'm trying to change labels for ggplot graph with facets, and am using a variable from the dataframe which is not faceted. The code is as belows-
iris %>%
group_by(Species) %>%
summarise(lbl = mean(Petal.Length)) %>%
select(lbl) %>%
unlist() -> lbls
lbls <- map2(unique(iris$Species), lbls, paste, sep = "\n")
iris %>%
ggplot(aes(x = Sepal.Length, y = Sepal.Width, group = 1)) +
geom_point() +
facet_wrap(~ Species, labeller = lbls)
However, this gives me the following error-
Error in cbind(labels = list(), list(`{`, if (!is.null(.rows) ||
!is.null(.cols)) { :
number of rows of matrices must match (see arg 2)
I've looked at the labeller function and different options but most of them seem to be for variables which are included in facets. Is there a way this can be done? Any leads appreciated, thanks!