mjg211 / phaseR

Development version of phaseR, an R package for phase plane analysis of one- and two-dimensional autonomous ODE systems
https://doi.org/10.32614/RJ-2014-023
Other
15 stars 3 forks source link

[WIP] Port phaseR to ggplot graphics #10

Closed tomicapretto closed 4 years ago

tomicapretto commented 4 years ago

Opening PR to track changes and discussion about porting current plots to ggplot2.

Do not review changed files because they're changing in the immediate future.

tomicapretto commented 4 years ago

Commit 1e0876ffec99fcaffbeb75f72d7f48692e521fe0 added two functions flowField2() and nullclines2(). The names aren't definite, I just didn't want to delete the original versions because these functions might be modified in the near future.

Now, you can do something like this:

library(magrittr)

func = function(t, state, parameters) {
  with(as.list(c(t, state, parameters)), {
    dx = a * x ** 2 + b * y ** 2 + c
    dy = d * x + e * y
    list(c(dx, dy))
  })
}
parameters = c(a = 1 , b = 1, c = -4, d = -2, e = 1)

flowField2(
  deriv = func,
  xlim = c(-3, 3),
  ylim = c(-3, 3),
  parameters = parameters,
  system = "two.dim") %>%
nullclines2(
  deriv = func, xlim = c(-3, 3), ylim = c(-3, 3),
  parameters = parameters, system = "two.dim", points = 400,
  add.legend = TRUE
)

And the output will be

example

These two functions also allow you to return the data.frames that are consumed by ggplot2. Instead of letting flowField2() and nullclines2() generate the plot for you, you take the data.frames and generate your own custom plot via ggplot2 (or via base graphics if you want)

Some questions that arise...

Well, those are some thoughts after the commit. The one that concerns me the most is the first, which is something I'd like to address during the next one or two weeks

mjg211 commented 4 years ago

Great work Tomas! Some thoughts on your points: