kevinwolz / hisafer

An R toolbox for the Hi-sAFe biophysical agroforestry model
6 stars 4 forks source link

add an option for simulation day rather than date in plot_hisafe_ts #147

Open mariegosme opened 4 years ago

mariegosme commented 4 years ago

For climate change studies, it could be usefull to compare simulations performed in current and future climate using plot_hisafe_ts, but with the simulation day rather than the actual date as x-axis. Maybe there's already an option to do that, but I haven't seen it. It would require of course that simulation runs are comparable (e.g. start at the same day of year) and trees are planted at the same simulation year, any other requirement that anybody can think of ? If @kevinwolz can't to it in a blink of the eye, I'll try to do it and propose a pull request...following the rules this time.

kevinwolz commented 4 years ago

I have wanted better x-axis labels for plot_hisafe_ts() from the beginning. It is very difficult, however, for two reasons:

(1) the function allows for so much flexibility (e.g. faceting by year, crop, simulation, or tree.id; cumulative vs. not; one-year simulations vs. multi-year simulations; zooming in on a specific date or doy range, etc.) and the x-axis must dynamically respond to these many situations to provide the most useful resolution/representation. Furthermore, ideally, it should do this dynamic response with no input from the user.

(2) ggplot2::scale_x_date(), which currently drives the x-axis scale in plots_hisafe_ts() is not as flexible as would be useful for us. ggplot2::scale_x_date() was introduced around the time I first created plots_hisafe_ts(), and it has been improved since then. Maybe those improvements help us maintain the flexibility we need??

Of course, we could also throw issue 1 out the window and concede that there are just too many possible use cases, along with the unknown subjective preferences of the user. In this case, we could add a new input parameter to plots_hisafe_ts() (with a logical default to ensure backwards compatibility) that allows the user to specifically specify the format of the x-axis labels. This parameter could specify some combination of the date_labels and date_breaks arguments of ggplot2::scale_x_date(), for example. But in the scenario, you are then relying on the user possibly having more knowledge about R and date specification than they actually have, which limits the usability of hisafer. So I don't know if this is a good idea.

Anyway, those are some initial thoughts! You'll see the mess in the code. Good luck!