# making a new method for the generic
# in this example, we enable adding text elements
S7::method(update_ggplot, list(element_text, class_ggplot)) <-
function(object, plot, ...) {
plot + theme(text = object)
}
# we can now use `+` to add our object to a plot
ggplot(mpg, aes(displ, cty)) +
geom_point() +
element_text(colour = "red")
# clean-up
Run the code above in your browser using DataLab