Skip to content

Commit 98dacf7

Browse files
jakob-rberndbischl
authored andcommitted
gg.objects only for plorExampleRun (#250)
1 parent b787080 commit 98dacf7

12 files changed

+30
-12
lines changed

R/plotExampleRun.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
#' each element a color for the type design, prop and seq respectivly.
6262
#' Default is red for the initial design, blue for allready proposed points
6363
#' and green for the actual iteration.
64+
#' @param gg.objects [\code{list)}]
65+
#' List of \code{gg} objects that should be added to all ggplots.
6466
#' @param ... [any]\cr
6567
#' Currently not used.
6668
#' @return Nothing.
@@ -69,7 +71,7 @@ plotExampleRun = function(object, iters, pause = TRUE,
6971
densregion = TRUE, se.factor = 1, single.prop.point.plots = FALSE,
7072
xlim = NULL, ylim = NULL,
7173
point.size = 3, line.size = 1,
72-
trafo = NULL, colors = c("red", "blue", "green"), ...) {
74+
trafo = NULL, colors = c("red", "blue", "green"), gg.objects = list(), ...) {
7375

7476
iters.max = object$control$iters
7577
if (missing(iters)) {
@@ -92,6 +94,7 @@ plotExampleRun = function(object, iters, pause = TRUE,
9294
# Helper to arrange plot via gridExtra and pause process
9395
arrangePlots = function(plots, multi.crit) {
9496
plots = Filter(Negate(isScalarNA), plots)
97+
plots = lapply(plots, addGgsToGgplot, gg.objects)
9598
n.plots = length(plots)
9699
if (n.plots > 1) {
97100
requirePackages("gridExtra", why = "plotExampleRun")
@@ -113,7 +116,7 @@ plotExampleRun = function(object, iters, pause = TRUE,
113116
# get rendered plot data
114117
plots = renderExampleRunPlot(object, iter = iter, densregion = densregion, se.factor = se.factor,
115118
single.prop.point.plots = single.prop.point.plots, xlim = xlim, ylim = ylim,
116-
point.size = point.size, line.size = line.size, trafo = trafo, colors = colors, ...)
119+
point.size = point.size, line.size = line.size, trafo = trafo, colors = colors, gg.objects = gg.objects, ...)
117120
if (!any(vlapply(plots, inherits, what = "ggplot"))) {
118121
# in this case we have multicrit multipoint proposal: list of plots for each proposed point
119122
for (jter in 1:length(plots)) {

R/renderExampleRunPlot_helpers.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,15 @@ addParegoWeightLines = function(pl, data.y, idx, opt.path, proposed.counter, rho
160160
# pl + geom_line(data = gg.line, aes(x = y1, y = y2), col = "blue", shape = 1)
161161
pl
162162
}
163+
164+
# @param g [ggplot object]
165+
# A normal ggplot object
166+
# @ggs [various ggplot objects]
167+
# Elements that you want to add to ggplot as custom scales or themes
168+
addGgsToGgplot = function(g, ggs) {
169+
if (!inherits(g, "gg")) return(g) #sometimes there are NAs
170+
for (gg in ggs) {
171+
g = g + gg
172+
}
173+
return(g)
174+
}

inst/examples/ex_1d_discrete_noisy.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ run = exampleRun(obj.fun, design = design, learner = lrn, control = ctrl,
4242
points.per.dim = 50L, show.info = TRUE)
4343

4444
print(run)
45-
plotExampleRun(run, pause = pause, densregion = TRUE)
45+
plotExampleRun(run, pause = pause, densregion = TRUE, gg.objects = list(theme_bw()))

inst/examples/ex_1d_noisy_numeric.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ run = exampleRun(obj.fun, design = design, learner = lrn,
3838

3939
print(run)
4040

41-
plotExampleRun(run, pause = pause, densregion = TRUE)
41+
plotExampleRun(run, pause = pause, densregion = TRUE, gg.objects = list(theme_bw()))

inst/examples/ex_1d_noisy_numeric_multifid.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ run = exampleRun(obj.fun, design = design, learner = lrn,
5151

5252
print(run)
5353

54-
res = plotExampleRun(run, pause = pause, densregion = TRUE)
54+
res = plotExampleRun(run, pause = pause, densregion = TRUE, gg.objects = list(theme_bw()))

inst/examples/ex_1d_numeric.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ design = generateDesign(6L, getParamSet(obj.fun), fun = lhs::maximinLHS)
2626
run = exampleRun(obj.fun, design = design, learner = lrn,
2727
control = ctrl, points.per.dim = 100, show.info = TRUE)
2828

29-
plotExampleRun(run, pause = pause, densregion = TRUE)
29+
plotExampleRun(run, pause = pause, densregion = TRUE, gg.objects = list(theme_bw()))

inst/examples/ex_1d_numeric_multipoint.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ run = exampleRun(obj.fun, design = design, learner = lrn,
3434

3535
print(run)
3636

37-
plotExampleRun(run, pause = pause, densregion = TRUE)
37+
plotExampleRun(run, pause = pause, densregion = TRUE, gg.objects = list(theme_bw()))

inst/examples/ex_2d_numeric.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ run = exampleRun(obj.fun, design = design, learner = lrn, control = ctrl,
2424

2525
print(run)
2626

27-
plotExampleRun(run, pause = pause)
27+
plotExampleRun(run, pause = pause, gg.objects = list(theme_bw()))

inst/examples/ex_2d_numeric_multipoint.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ run = exampleRun(obj.fun, design = design, learner = lrn, control = ctrl,
2727

2828
print(run)
2929

30-
plotExampleRun(run, pause = pause)
30+
plotExampleRun(run, pause = pause, gg.objects = list(theme_bw()))

inst/examples/ex_mixed.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ run = exampleRun(obj.fun, design = design, learner = lrn,
3535

3636
print(run)
3737

38-
plotExampleRun(run, pause = pause, densregion = TRUE)
38+
plotExampleRun(run, pause = pause, densregion = TRUE, gg.objects = list(theme_bw()))

0 commit comments

Comments
 (0)