简体   繁体   English

如何在R中的3D图中添加标签?

[英]How to add labels to a 3D plot in R?

I have data that I want to plot in 3 dimensions. 我有要绘制3维的数据。 I have two dataframes and I wish to plot data from both of them in the same graph (scales of all variables are similar, only one of the dataframes has all the outliers, for which I want to see the separation from the majority). 我有两个数据框,我希望在同一张图中绘制来自两个数据框的数据(所有变量的标度相似,只有一个数据框具有所有异常值,为此,我希望将其与多数分离。) I am attaching a sample of the data. 我附上数据样本。 Both dataframes have the same columns. 两个数据框具有相同的列。

  id  ele hap.700. hap.400.        HL        HW         IN       IOA
1 F031 1745       B2     BMP1 0.2701648 0.2831743 0.13052906 0.1860364
2 F032 1740       B2     BMP1 0.2903226 0.2985939 0.06823821 0.1546733
3 F084 2000       B3     BMP1 0.2379221 0.3864935 0.09090909 0.1802597
4 F189 2150       B3     BMP1 0.3370195 0.3712480 0.10110584 0.1827278
5 F200 2355       B3     BMP1 0.2813953 0.4000000 0.10872093 0.1680233
6 F085 2020       B4     BMP2 0.2659981 0.3595989 0.11652340 0.1757402

I used the following code for what I need in a 2D plot 我将以下代码用于2D图中所需的代码

x=data.frame(read.csv(file.choose()))   #Choose the first data.frame
plot(x$HL,x$HW,pch=19,col=as.factor(x$hap.700.)) #Plots the majority data
library(calibrate)
y=data.frame(read.csv(file.choose()))   #Choose the second data.frame
textxy(y$HL,y$HW,y$hap.700.)  #adds labels of the outgroups on the same plot

However, if I am trying to use textxy function in the rgl package, I am unable to do so. 但是,如果我尝试在rgl包中使用textxy函数,则无法这样做。 Is there any equivalent package for 3D plots that I can use to achieve what I am trying to do ? 我可以使用任何等效的3D绘图套件来实现自己想要做的事情吗?

Try this 尝试这个

library(rgl)
with(x, plot3d(HL, IN, HW, size = 10, col=as.factor(x$hap.700.)))
with(y, texts3d(HL, IN, HW, hap.700., cex = .5, adj = c(-.5, 0.5)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM