如何在R中绘制具有不同颜色的3D图表

时间:2016-07-14 15:34:46

标签: r

我有一个名为t:

的数据框
dput(t)
structure(list(timestamp = structure(c(1466306383, 1466306445, 
1466306507, 1466306569, 1466306631, 1466306693, 1466306755, 1466306817, 
1466306879, 1466306943, 1466307006, 1466307068, 1466307130, 1466307193, 
1466307255, 1466307317, 1466307379, 1466307442, 1466307504, 1466307566
), class = c("POSIXct", "POSIXt"), tzone = ""), cpuused = c(1.13007, 
1.13007, 1.13002, 1.12996, 1.1299, 1.12985, 1.12979, 1.12976, 
1.1297, 1.12965, 1.12959, 1.12953, 1.12947, 1.12942, 1.12936, 
1.1293, 1.12927, 1.12921, 1.12915, 1.1291), transratepersec = c(2640.77, 
2640.61, 2640.44, 2640.28, 2640.12, 2639.95, 2639.79, 2639.69, 
2639.53, 2639.36, 2639.19, 2639.03, 2638.86, 2638.7, 2638.54, 
2638.37, 2638.21, 2638.04, 2637.88, 2637.72), reqpersec = c(0.172818, 
0.172806, 0.172793, 0.172779, 0.172766, 0.172752, 0.172739, 0.172727, 
0.172714, 0.1727, 0.172687, 0.172673, 0.17266, 0.172646, 0.172633, 
0.17262, 0.172608, 0.172594, 0.172581, 0.172567), resptime = c(0.274, 
0.235, 0.234, 0.234, 0.236, 0.234, 0.235, 0.236, 0.236, 0.233, 
0.267, 0.235, 0.243, 0.235, 0.232, 0.233, 0.31, 0.233, 0.26, 
0.234)), .Names = c("timestamp", "cpuused", "transratepersec", 
"reqpersec", "resptime"), row.names = c(11653L, 19385L, 2624L, 
16106L, 13990L, 12724L, 9490L, 12720L, 19387L, 11656L, 13988L, 
9488L, 11650L, 5639L, 16104L, 15090L, 17156L, 4856L, 12722L, 
382L), class = "data.frame")

我想创建一个三维图表,其中x = reqpersec,y = cpuused,z = transrateperse,具有不同颜色的x,y和x,z。

我试过这个:

library(rgl)
attach(t)

plot3d(x=reqpersec, y=cpuused, z=transratepersec, type="p", col="red", xlab="ReqPerSec", ylab="CPU", zlab="TransRate", size=5, lwd=15, box=F)

它只给我一种颜色。任何想法如何轻松做到这一点?

我希望图像与此类似:

enter image description here

0 个答案:

没有答案