如何编辑散点图的图例?

How to edit the legend of a scatter plot?

我用传说做了一个情节。通过此代码:

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)

但是我的图表是这样的:

如何编辑它以使其看起来更好?
你能帮我解决一些问题吗?
谢谢你的帮助。

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

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

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

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)


最后,window 大小进行了调整,以便为图例留出更多空间。

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,但此设置将是一个很好的起点。