【问题标题】:Hiding the Legend in this Graph在此图中隐藏图例
【发布时间】:2022-07-04 14:08:53
【问题描述】:

我制作这张图是为了展示优化算法所取得的进展 (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)
  • “图例”似乎遮住了图表 - 是否有可能隐藏图例?

通常,使用 Base R 和 GGPLOT2 库制作的图表可以很容易地禁用它们的图例 - 但由于此处使用的绘图功能来自不同的库,我不确定是否可以禁用此图例。

谢谢!

【问题讨论】:

    标签: r data-visualization legend


    【解决方案1】:

    这应该有效: plot(GA, legend = FALSE)

    P.S,如果您不熟悉包功能,我总是发现使用 ??GA::plot 在控制台中查找 R 文档会很有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-09
      • 1970-01-01
      • 1970-01-01
      • 2018-07-17
      • 2014-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多