Question

I've a factor vector containing 25 unique variables for categorizing two numeric variables (x,y) I want to plot for each single factor a scatterplot

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

This function result in generating 63 identical graphs of overall data. I want 25 different graphs, one for each factor

Could you please help me, Thanks

EDIT: Example given

             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")
                 }
Was it helpful?

Solution

Not so tidy, but you may try something like:

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 your example, and

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

in your code.

OTHER TIPS

Is this what you're trying to achieve?

# 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"))
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top