From d700a6742525675f9ff7e3dcdbc8121283cb9bb1 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Wed, 22 Oct 2014 21:50:42 +0200 Subject: Save plots in different formats - Add possibility to save plots in different formats - Make it possible to exclude the legend from the plot - Update of the manual --- DESCRIPTION | 4 +-- GNUmakefile | 9 +++--- NEWS.md | 6 ++++ inst/GUI/gmkin.R | 72 +++++++++++++++++++++++++++++++++++++++--- vignettes/gmkin_manual.Rmd | 9 ++++-- vignettes/gmkin_manual.html | 9 +++--- vignettes/img/gmkin_start.png | Bin 71441 -> 98460 bytes vignettes/img/plotoptions.png | Bin 29540 -> 40268 bytes 8 files changed, 92 insertions(+), 17 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8acf6e7..7c7f47a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: gmkin Type: Package Title: GUI for Fitting Kinetic Models to Chemical Degradation Data with mkin -Version: 0.5-5 -Date: 2014-10-16 +Version: 0.5-6 +Date: 2014-10-22 Authors@R: c(person("Johannes", "Ranke", role = c("aut", "cre", "cph"), email = "jranke@uni-bremen.de"), person("Eurofins Regulatory AG", role = "cph")) diff --git a/GNUmakefile b/GNUmakefile index ad02272..0c74591 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -70,16 +70,17 @@ vignettes: vignettes/gmkin_manual.html sd: "$(RBIN)/Rscript" -e "library(staticdocs); build_site()" -move-sd: +move-sd: sd rm -rf $(SDDIR)/*;\ cp -r inst/web/* $(SDDIR); cp gmkin_screenshot.png $(SDDIR); cd $(SDDIR) && svn add --force . -r-forge: sd move-sd +r-forge: move-sd cd $(RFSVN) && svn commit -m 'update gmkin static documentation from github repository' -release: build +release: r-forge build cp $(TGZ) $(RFSVN)/www/repo/src/contrib; scp $(TGZ) qnap:projects/gmkin - @echo Now build gmkin on windows and copy the zip to the repo + @echo Now build gmkin on windows and copy the zip to the repo with + @echo scp qnap:projects/gmkin/$(PKGSRC)_$(PKGVERS).zip $(RFSVN)/www/repo/bin/windows/contrib/3.1 clean: $(RM) -r $(PKGNAME).Rcheck/ diff --git a/NEWS.md b/NEWS.md index 061c158..3c8d852 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# CHANGES in gmkin VERSION 0.5-6 + +## NEW FEATURES + +- The plot of the current fit and the residuals can be saved as pdf or png file, on windows also as a windows metafile (wmf) + # CHANGES in gmkin VERSION 0.5-5 ## BUG FIXES diff --git a/inst/GUI/gmkin.R b/inst/GUI/gmkin.R index 1a18be0..e0730cd 100644 --- a/inst/GUI/gmkin.R +++ b/inst/GUI/gmkin.R @@ -273,6 +273,8 @@ configure_fit_handler = function(h, ...) { f.gg.po.obssel <<- gcheckboxgroup(names(ftmp$mkinmod$spec), cont = f.gg.plotopts, checked = TRUE) show_plot("Initial", default = TRUE) + svalue(plot.ftmp.savefile) <<- paste(ftmp$ds$title, "_", ftmp$mkinmod$name, + ".", plot_format, sep = "") oldwidth <<- options()$width options(width = 90) svalue(f.gg.summary.filename) <<- "" @@ -790,24 +792,44 @@ ftmp$ds = ds[[ds.i]] stmp <- summary(ftmp) Parameters <- get_Parameters(stmp, FALSE) -plot_ftmp_png <- function() { - tf <- get_tempfile(ext=".png") +plot_ftmp <- function() { if(exists("f.gg.po.obssel")) { obs_vars_plot = svalue(f.gg.po.obssel) } else { obs_vars_plot = names(ftmp$mkinmod$spec) } - png(tf, width = 400, height = 400) + if(exists("f.gg.po.legend")) { + plot_legend = svalue(f.gg.po.legend) + } else { + plot_legend = TRUE + } plot(ftmp, main = ftmp$ds$title, obs_vars = obs_vars_plot, xlab = ifelse(ftmp$ds$time_unit == "", "Time", paste("Time in", ftmp$ds$time_unit)), ylab = ifelse(ds[[ds.i]]$unit == "", "Observed", paste("Observed in", ftmp$ds$unit)), + legend = plot_legend, show_residuals = TRUE) +} + +plot_ftmp_png <- function() { + tf <- get_tempfile(ext=".png") + png(tf, width = 400, height = 400) + plot_ftmp() dev.off() return(tf) } +plot_ftmp_save <- function(filename) { + switch(plot_format, + png = png(filename, width = 400, height = 400), + pdf = pdf(filename), + wmf = win.metafile(filename)) + plot_ftmp() + dev.off() + svalue(sb) <- paste("Saved plot to", filename, "in working directory", getwd()) +} + plot_confint_png <- function() { tf <- get_tempfile(ext=".png") png(tf, width = 400, height = 400) @@ -816,7 +838,34 @@ plot_confint_png <- function() { return(tf) } +plot_formats <- c("png", "pdf") +if (exists("win.metafile", "package:grDevices", inherits = FALSE)) { + plot_formats = c("wmf", plot_formats) +} +plot_format <- plot_formats[[1]] + plot.ftmp.gi <- gimage(plot_ftmp_png(), container = pf.p, width = 400, height = 400) +plot.ftmp.saveline <- ggroup(cont = pf.p, horizontal = TRUE) +plot.ftmp.savefile <- gedit(paste(ds[[ds.cur]]$title, "_", m[[m.cur]]$name, ".", + plot_format, sep = ""), + width = 40, cont = plot.ftmp.saveline) +plot.ftmp.savebutton <- gbutton("Save plot", cont = plot.ftmp.saveline, + handler = function(h, ...) { + filename <- svalue(plot.ftmp.savefile) + if (file.exists(filename)) + { + gconfirm(paste("File", filename, + "exists. Overwrite?"), + parent = w, + handler = function(h, ...) { + plot_ftmp_save(filename) + } + ) + } else { + plot_ftmp_save(filename) + } + }) +plot.space <- ggroup(cont = pf.p, horizontal = TRUE, height = 18) plot.confint.gi <- gimage(plot_confint_png(), container = pf.p, width = 400, height = 400) # Buttons and notebook area to the right {{{3 @@ -961,8 +1010,19 @@ f.gg.summary.listing <- ghtml(c("
", capture.output(stmp), "
"), options(width = oldwidth) # Plot options {{{4 -f.gg.plotopts <- ggroup(cont = f.gn, label = "Plot options", horizontal = FALSE) -f.gg.po.update <- gbutton("Update plot", +f.gg.plotopts <- ggroup(cont = f.gn, label = "Plot options", horizontal = FALSE, + width = 200) + +f.gg.po.format <- gcombobox(plot_formats, selected = 1, label = "File format", + cont = f.gg.plotopts, + handler = function(h, ...) { + plot_format <<- svalue(h$obj) + svalue(plot.ftmp.savefile) <<- gsub("...$", plot_format, + svalue(plot.ftmp.savefile)) + }) +plot_format <- svalue(f.gg.po.format) +f.gg.po.legend <- gcheckbox("legend", cont = f.gg.plotopts, checked = TRUE) +f.gg.po.update <- gbutton("Update plot", handler = function(h, ...) show_plot("Optimised"), cont = f.gg.plotopts) f.gg.po.obssel <- gcheckboxgroup(names(m[[m.cur]]$spec), cont = f.gg.plotopts, @@ -1006,6 +1066,8 @@ update_plotting_and_fitting <- function() { f.gg.po.obssel <<- gcheckboxgroup(names(ftmp$mkinmod$spec), cont = f.gg.plotopts, checked = TRUE) # Plot + svalue(plot.ftmp.savefile) <<- paste(ftmp$ds$title, "_", ftmp$mkinmod$name, + ".", plot_format, sep = "") show_plot("Optimised") } diff --git a/vignettes/gmkin_manual.Rmd b/vignettes/gmkin_manual.Rmd index af8a3b8..6522916 100644 --- a/vignettes/gmkin_manual.Rmd +++ b/vignettes/gmkin_manual.Rmd @@ -380,11 +380,16 @@ and pressing the button "Save summary". ### Plot options -In the tab "Plot options", the observed variables for which the data and the model fit should be -plotted can be selected as shown below. +In the tab "Plot options", the file format can be chosen, the legend can be +turned off, and the observed variables for which the data and the model fit +should be plotted can be selected as shown below. ![plot options](img/plotoptions.png) +On systems running the Windows operating system, the windows metafile (wmf) format +can be additionally chosen. Chaning the file format for plotting will also change +the extension of the proposed filename for saving the plot. + ### Confidence interval plots Whenever a new fit has been configured or a run of a fit has been completed, the plotting diff --git a/vignettes/gmkin_manual.html b/vignettes/gmkin_manual.html index cd66327..4e0f576 100644 --- a/vignettes/gmkin_manual.html +++ b/vignettes/gmkin_manual.html @@ -101,7 +101,7 @@ if (window.hljs && document.readyState && document.readyState === "complete") {
Model cost at call 1: 2388.077

which means that the first kinetic evaluation has been configured for fitting.

In the browser, you should see something like the screenshot below.

-

gmkin start

+

gmkin start

The statusbar at the bottom of the gmkin window shows, among others, the working directory that gmkin uses.

Note that the project file management area described below can be minimized by clicking on the arrows on the right hand side of its title bar. This may be helpful if the vertical size of your browser window is restricted.

@@ -195,7 +195,7 @@ if (window.hljs && document.readyState && document.readyState === "complete") {

If fitting with transformed fractions leads to a suboptimal fit, doing a first run without transforming fractions may help. A final run using the optimised parameters from the previous run as starting values (see comment on “Get initials from” above) can then be performed with transformed fractions.

The dropdown box “weight” specifies if and how the observed values should be weighted in the fitting process. If “manual” is chosen, the values in the “err” column of the dataset are used, which are set to unity by default. Setting these to higher values gives lower weight and vice versa. If “none” is chosen, observed values are not weighted. Please refer to the documentation of the modFit function from the FME package for the meaning of options “std” and “mean”.

The options “reweight.method”, “reweight.tol” and “reweight.max.iter” enable the use of iteratively reweighted least squares fitting, if the reweighting method is set to “obs”. Please refer to the mkinfit documentation for more details.

-

The drop down box “method.modFit” makes it possible to choose between the optimisation algorithms “Marq” (the default Levenberg-Marquardt implementation from the R package minpack.lm), “Port” (an alternative, also local optimisation algorithm) and “SANN” (the simulated annealing method - robust but inefficient and without a convergence criterion).

+

The drop down box “method.modFit” makes it possible to choose between the optimisation algorithms “Port” (the default in mkin versions > 0.9-33, a local optimisation algorithm using a model/trust region approach), “Marq” (the former default in mkin, a Levenberg-Marquardt variant from the R package minpack.lm), and “SANN” (the simulated annealing method - robust but inefficient and without a convergence criterion).

Finally, the maximum number of iterations for the optimisation can be adapted using the “maxit.modFit” field.

@@ -227,8 +227,9 @@ Model cost at call 37 : 371.2134

Plot options

-

In the tab “Plot options”, the observed variables for which the data and the model fit should be plotted can be selected as shown below.

-

plot options

+

In the tab “Plot options”, the file format can be chosen, the legend can be turned off, and the observed variables for which the data and the model fit should be plotted can be selected as shown below.

+

plot options

+

On systems running the Windows operating system, the windows metafile (wmf) format can be additionally chosen. Chaning the file format for plotting will also change the extension of the proposed filename for saving the plot.

Confidence interval plots

diff --git a/vignettes/img/gmkin_start.png b/vignettes/img/gmkin_start.png index 13c3613..c33af1a 100644 Binary files a/vignettes/img/gmkin_start.png and b/vignettes/img/gmkin_start.png differ diff --git a/vignettes/img/plotoptions.png b/vignettes/img/plotoptions.png index 4dcf025..e136fd8 100644 Binary files a/vignettes/img/plotoptions.png and b/vignettes/img/plotoptions.png differ -- cgit v1.2.1