In basic R you can add layers to the existing plot without creating a new one.
df <- data.frame(x = 1:10, y = runif(10))
plot(df, type = "l")
points(df, add = T)
The second line creates a plot and the third line adds points to the existing plot. In ggplot2:
my_plot <- ggplot(df, aes(x, y)) + geom_path()
my_plot
my_plot + geom_point()
The second line creates a plot and the third one creates another plot. Can I somehow add the points to the existing plot created by the second line? Is there something like add=TRUE
in ggplot?
The reason I want this behaviour is that using ggplot2 in shiny causes blinks in its animations.