简体   繁体   中英

How to add labels to a 3D plot in R?

I have data that I want to plot in 3 dimensions. 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

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. Is there any equivalent package for 3D plots that I can use to achieve what I am trying to do ?

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)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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