2011-10-02 66 views
2

我有一个关于在三维中生成R中的图形的问题。假设,我有一个csv格式文件中的以下数据;R中的三轴图形

CPU_Usage Power_Consumption(Watt) Bandwidth 
50  59      20MB 

现在我想,其中x轴表示CPU,用于代表此上的xyz轴,y表示功率& z表示的带宽。然后,我希望这些值在三轴图上连接在一起(用一条线)以形成一个三角形。这个数据中只有一行。如果有人能帮助我,我将不胜感激!

回答

1

你可以用scatterplot3d做到这一点(其中包括):

library(scatterplot3d) 

#first draw the lines of the triangle 
#using type="l" Since we are drawing a 
#shape, include the first point twice to 
#close the polygon 
q <- scatterplot3d(c(50, 0, 0, 50), 
    c(0, 59, 0, 0), c(0, 0, 20, 0), 
    xlim=c(0, 60), ylim=c(0, 60), zlim=c(0, 60), type="l", 
    xlab="CPU Usage", ylab="Power Consumption", zlab="Bandwidth", 
    box=FALSE) 

#now add the points. scatterplot3d creates a list, 
#one element of which is a function that operates 
#on the existing chart, q, adding points: 
q$points3d(c(50, 0, 0), c(0, 59, 0), c(0, 0, 20)) 

当然,如果你需要做这些不止一个,你可以从你的数据拉点,而不是硬编码它们。我认为硬编码会使它更具可读性。

+0

谢谢杰森!!! :)的工作方式正是我想象的! –