Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Hiding the Legend in this Graph

I made this graph to demonstrate the progress being made by an optimization algorithm (https://rstudio-pubs-static.s3.amazonaws.com/132872_620c10f340f348b88453d75ec99960ff.html):

library(GA)
data("eurodist", package = "datasets")
D <- as.matrix(eurodist)


tourLength <- function(tour, distMatrix) {
   tour <- c(tour, tour[1])
   route <- embed(tour, 2)[,2:1]
   sum(distMatrix[route])
}

#Firness function to be maximized

tspFitness <- function(tour, ...) 1/tourLength(tour, ...)

GA <- ga(type = "permutation", fitness = tspFitness, distMatrix = D,
          min = 1, max = attr(eurodist, "Size"), popSize = 50, maxiter = 5000,
          run = 500, pmutation = 0.2)

plot(GA)

enter image description here

  • The "legend" seems to be obscuring the graph – is it somehow possible to hide the legend?

Normally, graphs that are made using Base R and GGPLOT2 libraries can have their legends disabled pretty easily – but since the graphing function being used here is from a different library, I am not sure if it is possible to disable this legend.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thank you!

>Solution :

This should work:
plot(GA, legend = FALSE)

P.S, if you are not familiar with a package function I always find it helpful to look up the R-documentation in the console using ??GA::plot

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading