I am running into an issue with ggplot.
I have a ggplot object x1
that I assign to variable y1
I then modify x1
, and assign it to y2
.
As a result of my change to x1
, y1
is also changed. This is throwing me off a bit, not sure if I am understanding how variables are linked in R. Example below:
x1 <- ggplot() + geom_vline(xintercept = 10)
y1 <- x1
# x1 and y1 print plot with vline at 10
x1[["layers"]][[1]][["data"]][["xintercept"]] <- 20
y2 <- x1
# x1 y2 and y1 print plot with vline at 20
# why is y1 being modified?
Any input is appreciated.