I have a nested tibble that stores data, a grouping variable and a plot illustrating the data.
Consider the following example:
library(dplyr)
library(tibble)
library(ggplot2)
test <- tibble(x=c(1,2), p=list(qplot(1), qplot(2)))
Column p
are the plots, column x
is the grouping variable.
I would like to provide a title to each plot, based on the value of x
in the respective row.
I tried using dplyr's mutate function:
mutate(test, p=p+labs(title=paste("Group:", x)))
However, this specific code fails with Error: non-numeric argument to binary operator
.
How can I add another layer to the stored ggplots within the tibble?