GA (version 3.0.2)

plot.ga-method: Plot of Genetic Algorithm search path

Description

The plot method for ga-class objects gives a plot of best and average fitness values found during the iterations of the GA search.

Usage

# S4 method for ga
plot(x, y, ylim, cex.points = 0.7, 
     col = c("green3", "dodgerblue3",  adjustcolor("green3", alpha.f = 0.1)),
     pch = c(16, 1), lty = c(1,2), legend = TRUE, grid = graphics:::grid, …)

Arguments

x

An object of class "ga".

y

Not used.

ylim

A vector of two values specifying the limits on the y-axis.

cex.points

The magnification to be used for points.

col

The colors to be used for best and average fitness values.

pch

The type of points to be used for best and average fitness values.

lty

The type of lines to be used for best and average fitness values.

legend

A logical specifying if a legend should be included.

grid

A function for grid drawing of NULL to avoid drawing one.

Further arguments, currently not used.

Value

The method invisibly return a data.frame with the iterations and summary statistics for the fitness function evaluated at each iteration.

Details

Plot best and average fitness values at each iteration of GA search.

See Also

ga, ga-class.

Examples

Run this code
# NOT RUN {
# See examples in help(ga)

# The following code shows how to obtain graphs using the 
# ggplot2 plotting system 
# }
# NOT RUN {
GA <- ga(...)
out <- plot(GA)
library(reshape2)
df <- melt(out[,c(1:3,5)], id.var = "iter")
library(ggplot2)
ggplot(df, aes(x = iter, y = value, group = variable, colour = variable)) +
  xlab("Generation") +  ylab("Fitness values") +
  geom_point(aes(shape = variable)) + 
  geom_line(aes(lty = variable)) +
  scale_colour_brewer(palette = "Set1") +
  theme_bw() +
  theme(legend.title = element_blank())
# }

Run the code above in your browser using DataCamp Workspace