77# ' Objects of classes \code{tabu} and \code{simulatedAnnealing} produce a
88# ' single plot which show the changes in the objective function across each
99# ' iteration of the algorithm. Objects of class \code{antcolony} can produce
10- # ' up to three plots which show the changes in the pheromone levels for each
10+ # ' up to four plots which show the changes in the pheromone levels for each
1111# ' item, changes in the average standardized regression coefficients of the
12- # ' model, and changes in the amount of variance explained in the model across
13- # ' each iteration of the algorithm.
12+ # ' model (gammas and betas) , and changes in the amount of variance explained
13+ # ' in the model across each iteration of the algorithm.
1414# '
1515# ' These functions do not currently allow users to modify the resulting
1616# ' plots directly, but the objects produces are \pkg{ggplot2} objects which
1717# ' should allow for additional user customization.
1818# '
1919# ' @param x An object with one of the following classes: \code{antcolony},
2020# ' \code{tabu}, or \code{simulatedAnnealing}.
21- # ' @param type A character string. One of "all", "pheromone", "gamma", or
21+ # ' @param type A character string. One of "all", "pheromone", "gamma", "beta", or
2222# ' "variance". Matched literally. Only used with objects of class \code{antcolony}.
2323# ' @param ... Not used with the current S3 method implementation.
2424# ' @name plot
2727
2828plot.antcolony <- function (x , type = " all" , ... ) {
2929 summary_results <- x [[2 ]]
30- pheromone_plot = gamma_plot = variance_plot = NULL
30+ pheromone_plot = gamma_plot = beta_plot = variance_plot = NULL
3131 item_pheromone_names <-
3232 grep(" Pheromone" , names(summary_results ), value = TRUE )
3333
@@ -87,6 +87,28 @@ plot.antcolony <- function(x, type = "all", ...) {
8787 )
8888 }
8989
90+ if (type %in% c(" all" , " beta" )) {
91+ beta_plot <-
92+ ggplot2 :: ggplot(summary_results ,
93+ ggplot2 :: aes_string(x = " run" , y = " mean.beta" )) +
94+ ggplot2 :: geom_smooth(fullrange = TRUE , se = FALSE , na.rm = T ) +
95+ ggplot2 :: ylab(expression(" Mean " * beta )) +
96+ ggplot2 :: ggtitle(expression(" Smoothed Changes in Mean " * beta )) +
97+ ggplot2 :: geom_text(ggplot2 :: aes(label = ifelse(
98+ summary_results $ run %in% c(1 , max(summary_results $ run )),
99+ round(summary_results $ mean.beta , 3 ), " "
100+ )), vjust = 0 , na.rm = T ) +
101+ ggplot2 :: theme_bw() +
102+ ggplot2 :: theme(
103+ legend.position = " none" ,
104+ plot.title = ggplot2 :: element_text(
105+ size = 23 ,
106+ face = " bold" ,
107+ hjust = .5
108+ )
109+ )
110+ }
111+
90112 if (type %in% c(" all" , " variance" )) {
91113 variance_plot <-
92114 ggplot2 :: ggplot(summary_results ,
@@ -109,7 +131,8 @@ plot.antcolony <- function(x, type = "all", ...) {
109131 )
110132 }
111133
112- plots <- list (" Pheromone" = pheromone_plot , " Gamma" = gamma_plot , " Variance" = variance_plot )
134+ plots <- list (" Pheromone" = pheromone_plot , " Gamma" = gamma_plot ,
135+ " Beta" = beta_plot , " Variance" = variance_plot )
113136 return (plots )
114137
115138}
0 commit comments