[英]Labeling points and defining group colors using scatter3D() function from plot3D library
由于您没有提供数据,因此无法提供与您的问题直接相关的答案。 始终建议使用dput()
来提供至少一部分数据。 数据图片无法提供有用的信息。 还要指出您已加载的包。 在这种情况下,它很可能是你已经装载plot3D
包含了scatter3D
功能。
scatter3D
的手册页提供了您所有问题的答案 ( ?scatter3D
),但它很详细,可能难以遵循。 研究手册页上提供的示例,以下内容似乎可以完成您想要的。 它使用 R 提供的USArrests
数据集:
library(plot3D)
data(USArrests)
UP <- cut(USArrests$UrbanPop, breaks=quantile(USArrests$UrbanPop), include.lowest=TRUE)
这将加载数据集并从变量UrbanPop
创建一个分类变量。 现在基本情节:
with(USArrests, scatter3D(Murder, Assault, Rape, colvar = as.numeric(UP),
col = c("red", "green", "blue", "violet"), theta = 60, phi = 20,
xlab = "Murder", ylab = "Assault", zlab = "Rape", main = "USA arrests",
cex = 1, pch=16, bty = "g", ticktype = "detailed",
d = 2, clab = "Urban Population", adj = 0.5, font = 2,
colkey=list(at = c(1.4, 2.1, 2.9, 3.6), side = 1,
addlines = TRUE, length = 0.75, width = 0.5,
labels = c("1st Quart", "2nd Quart", "3rd Quart", "4th Quart"))))
这将创建基本图,其中圆圈由每个州的城市人口百分比的四分位数着色。 获取标记图例的位置 ( at=
) 需要一些反复试验。 现在我们添加文本标签:
with(USArrests, text3D(Murder, Assault, Rape, colvar = as.numeric(UP),
col = c("red", "green", "blue", "violet"), colkey=FALSE,
labels = state.abb, cex = .75, adj=-.5, add=TRUE))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.