R: update the graph of [xy] lims with the addition of new dots () or lines ()?

Background:

I use the Monte Carlo simulation to show that a certain process (cumulative average) does not converge with time and often diverges divergingly in the simulation (expectation of a random variable = infinity). I want to build about 10 of these simulations on a line chart, where the x axis has an iteration number and the y axis has a cumulative value to this point.

Here is my problem:

I launched the first simulation (each simulator having 10,000 iterations), and plotted the main graph based on its current range. But often, one of the simulations will have a range several orders of magnitude greater than the first, so the plot flies out of the original range. So, is there a way to dynamically update a ylim or xlim chart when adding a new set of points or lines?

I can think of two workarounds for this: 1. Save each simulation, then select the one that has the largest range, and build a basic graph (not elegant, and I would have to store a lot of data in memory, but would probably be friendly to the laptop [[EDIT: as Marek points out, this is not an example with intensive memory, but if you know of a good solution that will support much more iterations, so this becomes a problem (think about high dimensional tracks that require much larger samples MC for Conway Gentz), then jump right into]] ). 2. Find a seed that seems to build a beautiful version of it, and set ylim manually, which will make the demonstration reproducible.

, - , . , , , R. ?

+3
2

, , , - , . , ( ggplot2), . ggplot2.

require(ggplot2)

:

foo <- as.data.frame(cbind(data=rnorm(100), numb=seq_len(100)))

ggplot :

p <- ggplot(as.data.frame(foo), aes(numb, data)) + layer(geom='line')
p

foo <- as.data.frame(cbind(data=rnorm(200), numb=seq_len(200)))

p <- p + geom_line(aes(numb, data, colour="red"), data=as.data.frame(foo))

p
+5

(1) - . , . , , , , xlim ylim.

, ts() () /. :

alt text

0

Source: https://habr.com/ru/post/1718526/


All Articles