I tried to reproduce this example on how to use grid.arrange with two plots, with the sole adjustment that I change some of my data in between. The strange thing is that this changes the first plot that I stored. An example:
require(data.table)
require(ggplot2)
dt <- data.table(x=1:200, y=rnorm(200)) # Sample data
t1 <- qplot(y, data=dt) # Histogram of y
t1 # Show plot
dt[, y := x] # Change y to x
t1 # t1 changed...
I'm assuming that this is somehow intended behavior of ggplot2. Hence, my question is whether it is somehow possible to make t1
persistent to this change, i.e., to store the plot in a way that it doesn't change if the underlying data is changed.
My use case is an rmarkdown
file in which I want to show the unchanged and changed variable side by side.