我用scatter3d函数在R中绘制了一个三维散点图。现在,我要在三维散射点上绘制标签,例如每个点的ID都在它旁边,即"1","2“等等。
以下是我尝试过的:
library("car")
library("rgl")
scatter3d(geometry[,1],geometry[,2],geometry[,3] , surface=FALSE, labels = rownames(geometry), id.n=nrow(geometry))这个教程说,添加参数labels=rownames(geometry), id.n=nrow(geometry)应该在每个点上显示标签,但这不起作用。
编辑:
我上传了坐标文件这里,你可以这样读它
geometry = read.csv("geometry.txt",sep = " ")
colnames(geometry) = c("x","y","z")编辑:
实际上,即使是教程中的示例也没有标注点,也没有生成显示的情节。这个包裹可能有什么问题。
scatter3d(x = sep.l, y = pet.l, z = sep.w,
surface=FALSE, labels = rownames(iris), id.n=nrow(iris))发布于 2018-10-01 16:07:30
如果您想使用scatter3d以外的任何其他函数,我可以给您一个快速修复。这可以使用plot3d和text3d函数来实现。我已经提供了如何实现它的基本代码块。您可以根据您的需要定制它。
plot3d(geometry[,1],geometry[,2],geometry[,3])
text3d(geometry[,1],geometry[,2],geometry[,3],rownames(geometry))
points3d(geometry[,1],geometry[,2],geometry[,3], size = 5)发布于 2020-10-04 04:18:17
经过一番周旋之后,我得到了它(如果你感兴趣的话,我也有plot_ly的方法)
test2 <- cbind(dataSet[,paste(d)],set.final$Groups,test)
X <- test2[,1]
Y <- test2[,2]
Z <- test2[,3]
# 3D plot with the regression plane
scatter3d(x = X, y = Y, z = Z, groups = test2$`set.final$Groups`,
grid = FALSE, fit = "linear",ellipsoid = FALSE, surface=FALSE,
surface.col = c("green", "blue", "red"),
#showLabels(x = x, y = y, z = z, labels=test2$test, method="identify",n = nrow(test2), cex=1, col=carPalette()[1], location=c("lr"))
#labels = test2$test,
id=list(method = "mahal", n = length(test2$test), labels = test2$test)
#id.n=nrow(test2$test)
)
#identify3d(x = X, y = Y, z = Z, labels = test2$test, n = length(test2$test), plot = TRUE, adj = c(-0.1, 0.5), tolerance = 20, buttons = c("right"))
rglwidget()https://stackoverflow.com/questions/52590410
复制相似问题