|
21 | 21 | #' |
22 | 22 | #' @examples |
23 | 23 | #' \donttest{ |
24 | | -#' if (require("ggplot2", quietly = TRUE)) { |
25 | 24 | #' # Generate toy data and customize plots. |
26 | 25 | #' n <- 500 |
27 | 26 | #' K <- 1 |
|
30 | 29 | #' cost <- 1 |
31 | 30 | #' |
32 | 31 | #' # Fit Qini curves. |
33 | | -#' qini.avg <- maq(reward, cost, scores, R = 200, target.with.covariates = FALSE) |
34 | 32 | #' qini <- maq(reward, cost, scores, R = 200) |
| 33 | +#' qini.avg <- maq(reward, cost, scores, R = 200, target.with.covariates = FALSE) |
35 | 34 | #' |
36 | | -#' # In some settings we may want to plot using one of R's many plot libraries. |
37 | | -#' # The plot method invisibly returns the plot data we can use for this purpose. |
| 35 | +#' # The plot method invisibly returns the plot data as a data.frame, |
| 36 | +#' # which allows for custom plotting with external libraries. |
38 | 37 | #' df.qini.baseline <- plot(qini.avg) |
39 | | -#' df.qini <- plot(qini, add = TRUE, col = 2) |
| 38 | +#' df.qini <- plot(qini, add = TRUE, col = "red") |
40 | 39 | #' |
41 | 40 | #' # Make an alternate plot style, using, for example, ggplot. |
| 41 | +#' if (require("ggplot2", quietly = TRUE)) { |
42 | 42 | #' ggplot(df.qini, aes(x = spend, y = gain)) + |
43 | 43 | #' geom_ribbon(aes(ymin = gain - 1.96 * std.err, |
44 | 44 | #' ymax = gain + 1.96 * std.err), |
|
48 | 48 | #' xlab("Fraction treated") + |
49 | 49 | #' geom_line(data = df.qini.baseline, aes(x = spend, y = gain), lty = 2) |
50 | 50 | #' } |
51 | | -#' } |
52 | 51 | #' |
| 52 | +#' # `scale_maq()` rescales policy gain curves for specific application units. |
| 53 | +#' # Plot policy values for a maximum allocation of, for example, 500 units. |
| 54 | +#' plot(scale_maq(qini, 500), xlab = "Units treated") |
| 55 | +#' } |
53 | 56 | #' @method plot maq |
54 | 57 | #' @export |
55 | 58 | plot.maq <- function(x, |
|
0 commit comments