Say I have a dataframe:
df <- data.frame(x=1:10, y=4:13)
p <- ggplot(df,aes(x,y)) + geom_point()
Now I want to add many things to this graph, so I use a big paste function and print the output. Just as an example, say I wanted to add the word 'bananas' inside the x axis label.
x <- "bananas"
print(paste0("+ xlab('Price of", x[1], "')"), quote=F)
If I try:
p + print(paste0("+ xlab('Price of", x[1], "')"), quote=F)
then it obviously does not work. But is there a way of adding the output of this function to the ggplot object 'p' without cutting/pasting from the console?
i.e. so we automatically can execute:
p + xlab('Price ofbananas')