If I run this code the output is obviously a plot.
> p <- ggplot(mtcars, aes(mpg, hp)) +
+ geom_line()
> p
Storing variables for plots can be useful. If this was a more complex plot I might want to see what I declared for p later down the line, for example to debug the theme of a plot. Using View(p) or str(p) doesn't give a good overview at all.
Is there any way that I can see what I declared for ggplot variables like this? Or do I have to actually Ctrl-F my R file in order to manually look up what I did?
Edit: This should make my question more clear:
f <- function (x) {
result <- x+2
return(result)
}
library(ggplot2)
p <- ggplot(mtcars, aes(mpg, hp)) +
geom_line()
#printing f shows me the original form of the variable the way I defined it
print(f)
#printing p does not show me the original form of the variable the way I defined it, but rather executes it
print(p)
#what function do I need to use on p in order to produce the same result as for print(f)?