1 |
dataplot |
|
title |
|
ylab |
|
xlab |
|
includeMean |
|
includeWorst |
|
includeStdDev |
|
includeBestComparision |
|
invert |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (dataplot, title = NULL, ylab = NULL, includeMean = TRUE,
includeWorst = TRUE, includeStdDev = TRUE, includeBestComparision = TRUE,
invert = FALSE)
{
g = dataplot$generation
invertValue = 1
if (invert)
invertValue = -1
temp <- data.frame(Generation = c(seq(1, g)), Statistic = c(rep("best",
g)), StatisticalPoints = c(invertValue * dataplot$best[1:g]))
if (includeMean)
temp <- rbind(temp, data.frame(Generation = c(seq(1,
g)), Statistic = c(rep("mean", g)), StatisticalPoints = c(invertValue *
dataplot$mean[1:g])))
if (includeWorst)
temp <- rbind(temp, data.frame(Generation = c(seq(1,
g)), Statistic = c(rep("worst", g)), StatisticalPoints = c(invertValue *
dataplot$worst[1:g])))
if (includeStdDev)
temp <- rbind(temp, data.frame(Generation = c(seq(1,
g)), Statistic = c(rep("std", g)), StatisticalPoints = c(invertValue *
dataplot$stdDev[1:g])))
minY = min(temp$StatisticalPoints)
maxY = max(temp$StatisticalPoints)
pl <- ggplot(temp, aes(x = Generation, y = StatisticalPoints,
group = Statistic, colour = Statistic)) + geom_line(aes(linetype = Statistic)) +
geom_point(aes(shape = Statistic, size = Statistic)) +
scale_x_continuous(limits = c(0, g)) + scale_y_continuous(limits = c(minY -
(maxY - minY) * 0.05 * 0.5 * (!invert) * includeBestComparision,
maxY)) + scale_linetype_manual(values = c(mean = "solid",
best = "solid", worst = "solid", std = "blank")) + scale_shape_manual(values = c(mean = 1,
best = 1, worst = 1, std = 20)) + scale_size_manual(values = c(mean = 0,
best = 0, worst = 0, std = 1)) + scale_color_manual(values = c(mean = "blue",
best = "red", worst = "purple", std = "black"))
pl <- pl + ylab(ylab)
pl <- pl + ggtitle(title)
if (includeBestComparision)
pl <- pl + geom_hline(yintercept = min(dataplot$best),
lty = 2) + annotate("text", x = 1, y = min(dataplot$best) -
(maxY - minY) * 0.025 * 0.5, hjust = 0, size = 3,
color = "black", label = paste("Best solution:",
min(dataplot$best)))
print(pl)
return(pl)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.