【问题标题】:How to edit the legend of a scatter plot?如何编辑散点图的图例?
【发布时间】:2017-12-17 08:12:05
【问题描述】:

我用图例做了一个情节。通过这段代码:

scatter3d(x = red, y = green, z = blue, groups = C1class$V1, surface. col = 1:21,
      grid = FALSE, surface = FALSE)
legend3d("right", legend = levels(C1class$V1),
   col = rainbow(21), pch = 16, inset = -0.25, xpd = TRUE)

但我的图表是这样的:

如何编辑它以使其看起来更好?
你能帮我用一些功能来修复它吗?
谢谢你的帮助。

【问题讨论】:

  • 您希望它是什么样的?你能提供一些样本数据来复制你的情节吗?
  • 我想为情节制作可见的图例。

标签: r legend scatter3d


【解决方案1】:

你没有提供你的数据,所以我不能准确地测试你的问题, 但我认为下面的示例将帮助您解决问题。

我认为您的问题源于包含参数inset = -0.25。 那就是将图例移出显示区域。看着你的照片, 我认为你这样做的原因是因为否则 图例覆盖了散点图的一部分。解决此问题的另一种方法是使用windowRect 调整绘图区域以允许更多空间。

像你这样的情节,传说被砍掉了。

scatter3d(x = iris[,1], y = iris[,2], z = iris[,3], groups = iris[,5], 
    surface.col = rainbow(3), grid = FALSE, surface = FALSE)
legend3d("right", legend = levels(iris[,5]),
   col = rainbow(3), inset = -0.25, pch = 16, xpd = TRUE)


没有缩进的第二个情节。现在图例与情节重叠。

scatter3d(x = iris[,1], y = iris[,2], z = iris[,3], groups = iris[,5], 
    surface.col = rainbow(3), grid = FALSE, surface = FALSE)
legend3d("right", legend = levels(iris[,5]),
   col = rainbow(3), pch = 16, xpd = TRUE)


最后,调整窗口大小,为图例留出更多空间。

par3d(windowRect = c(100, 100, 600, 350))
scatter3d(x = iris[,1], y = iris[,2], z = iris[,3], groups = iris[,5], 
    surface.col = rainbow(3), grid = FALSE, surface = FALSE)
legend3d("right", legend = levels(iris[,5]),
   col = rainbow(3), pch = 16, xpd = TRUE)

您可能需要针对您的数据以不同方式调整windowRec,但此设置将是一个很好的起点。

【讨论】:

  • 非常感谢。对我帮助很大。
猜你喜欢
  • 2021-10-28
  • 2020-06-06
  • 2013-06-29
  • 1970-01-01
  • 2014-09-08
  • 1970-01-01
  • 1970-01-01
  • 2017-06-22
相关资源
最近更新 更多