2011-10-02 67 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

謝謝傑森!!! :)的工作方式正是我想象的! –