I am trying to copy a ggplot object and then change some properties of a new copied object, for example, a colored line to red.
Assume this code:
df = data.frame(cbind(x=1:10, y=1:10)) a = ggplot(df, aes(x=x, y=y)) + geom_line() b = a
Then, if I change the color of the string of variable a
a$layers[[1]]$geom_params$colour = "red"
it also changes color b
> b$layers[[1]]$geom_params$colour [1] "red"
I would like to have two different objects a and b with different characteristics. So, to do it right, I would need to call the plot again for b using b = ggplot(df, aes(xy, y=z)) + geom_line() . However, at this time, there is no way in the algorithm to find out the command plot ggplot(df, aes(x=x, y=y)) + geom_line()
Do you know what's wrong with that? Are ggplot objects handled differently?
Thanks!
source share