2014-04-24 26 views
0

我已經包含用於分類兩個數值變量(X,Y) 25個獨特的變量我要繪製的每個單因素散點圖週期爲展示根據因素

for (factor in Coordinates$matrixID) { 
    dev.new() 
    plot(grid, type = "n") 
vectorField(Coordinates$Angle,Coordinates&Length,Coordinates$x,Coordinates$y,scale=0.15, headspan=0, vecspec="deg") 
    } 
一個因子矢量的數目多個圖形

該功能可生成63個相同的整體數據圖。我想25個不同的圖形,每一個因素

能否請你幫我, 感謝

編輯:實例給出

   library(VecStatGraphs2D) 
     Data <- data.frame(
     x = sample(1:100), 
     y = sample(1:100), 
     angle = sample(1:100), 
     lenght = sample(1:100), 
     matrixID = sample(letters[1:25], 20, replace = TRUE)) 

      for (factor in matrixID) { 
       dev.new()  
       plot(grid, type = "n") V 
VectorField(Data$angle,Data$lenght,Data$x,Data$y,scale=0.15,headspan=0, vecspec="deg") 
       } 
+0

你可以提供(你的數據的一個樣本)作爲[一個可重複的例子]的一部分(http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) ?另外,「包含用於分類兩個數字變量的25個唯一變量的因子向量」是什麼意思? – Thomas

回答

0

沒有那麼整齊,但是你可以嘗試類似:

library(plotrix) 
library(VecStatGraphs2D) 
Data <- data.frame(
     x = sample(1:100), 
     y = sample(1:100), angle = sample(1:100), lenght = sample(1:100), 
      matrixID = sample(letters[1:4], 20, replace = TRUE)) 

for (i in unique(Data$matrixID)) 
    { 
    dev.new() 
    Data1 <- subset(Data, matrixID == i)  
    plot(0:100, type = "n") 
    vectorField(Data1$angle,Data1$lenght,Data1$x,Data1$y,scale=0.15, headspan=0, vecspec="deg") 
    } 

爲你的榜樣,並

for (i in unique(Coordinates$matrixID)) 
    { 
    dev.new() 
    Coordinates1 <- subset(Coordinates, matrixID == i) 
    plot(grid, type = "n") 
    vectorField(Coordinates1$Angle,Coordinates1&Length,Coordinates1$x,Coordinates1$y,scale=0.15, headspan=0, vecspec="deg") 
    } 
在你的代碼

+0

它的工作正常! – Borexino

0

這是你想達到什麼樣的?

# Dummy dataset 
library(plotrix) 
Data <- data.frame(
x = sample(1:100), 
y = sample(1:100), angle = sample(1:100), lenght = sample(1:100), matrixID = sample(letters[1:4], 20, replace = TRUE)) 

# Get the levels of matrixID 
lev <- levels(Data$matrixID) 

# Plot each graph 
for (i in lev) { 
    temp <- subset(Data,matrixID==i) 
    plot(temp$x,temp$y,type="n", main=i) 
    with(temp, vectorField(u=angle,v=lenght,x=x,y=y,scale=0.15,headspan=0, vecspec="deg")) 
    } 
+0

我這麼認爲,但我覺得:在plot.new()中出現錯誤:figure margins too large – Borexino

+0

所以只需刪除par(mfrow ...)行來在單個圖形窗口中生成每個圖形(我編輯了上面的代碼所以你不會得到'圖邊距'錯誤。 – Benoit