updated plot function with log transformation ~/R/plot.R
Hi Stefan, I'm happy to write you. I have some time today and had some time with Thomas at the conference. I update 12 lines on the plot function adding an argument called log_transform. This allows to change the y axis to log. This is handy in our phageEX when dealing with large populations as phages, maybe could be used if vectors are also modelled. I haven't update the others ## ' comments and files to roxygenise. Maybe you can evaluate this first try and then work a little more on the other files. I used this simple example to see, how it looks like. Maybe we could write a simple phage example, to be more aplicable to real world examples.
Example usage of the modified plot function
model <- SIR(u0 = data.frame(S = rep(10000, 10), I = rep(10, 10), R = rep(10, 10)), tspan = 1:24, beta = 0.8, gamma = 0.077) result <- run(model)
Test the updated plot function with log transformation
par(mfrow = c(2, 1)) plot(result, log_transform = FALSE) plot(result, log_transform = TRUE) par(mfrow = c(1, 1))
Thanks Alfredo. I like your suggestion to make it possible to log-transform the data. I'll take a closer look and review the code.
Hi Stefan, I removed the trailing lines, then used the log from base R. There were some problems in the arguments, the plot was behaving correctly but a warning appared: "plot(result)
Error in plot.window(...) : "log=" specification must be character. . "
I solved them making modifications in two places, plot_method and plot_data:
-
plot() Method for SimInf_model: Added a default value for the log argument (log = "") to ensure it behaves like the base R plot() function. Ensured the log argument is passed explicitly to init_plot_argv() and plot_data().
-
plot_data() Function: Extracted the log argument from argv and passed it explicitly to the plot() function. Removed the log argument from argv to prevent it from being passed to lower-level functions like lines() or polygon().
I did not update the vignettes: "Argument names in code not in docs: log Mismatches in argument names: Position: 10 Code: log Docs: ... "
Hope this helps!
- Testing:
Example usage of the modified plot function
model <- SIR(u0 = data.frame(S = rep(10000, 10), I = rep(10, 10), R = rep(10, 10)), tspan = 1:100, beta = 0.8, gamma = 0.077)
result <- run(model) trajectory(result)
Test the updated plot function with log transformation
plot(result)
par(mfrow = c(4, 2)) plot(result, , main = "Base plot") plot(result, log = "y", main = "Log Y-Axis") plot(result, log = "x", main = "Log X-Axis") plot(result, log = "y", ylim = c(1, 10000), main = "Log Y-Axis and limits") plot(result, log = "xy", ylim = c(1, 10000), main = "Logarithmic X&Y-Axis") plot(result, log = "x", ylim = c(1, 20), main = "Log X-Axis and limits") plot(result, log = "y", ylim = c(1, 500), main = "Log Y-Axis and limits") plot(result, ~ S, log = "y", ylim = c(1, 10000), main = "S") par(mfrow = c(1, 1))
Hi, thanks for the update. The SimInf.Rcheck folder has accidentally been included in the commit. Could you please have a look at that, and then I'll take a look on your update.
Dear Stefan, thanks for checking. The folder is deleted. Hope you can see the changes more clearly now. Thanks.
Thanks @alfredojavier55 for the update, I will check later this week.
Good morning @stewid, yesterday's changes were updated.
@alfredojavier55 Thanks