我有一个因子向量,包含25个唯一变量,用于分类两个数值变量(x,y) 我想为每个单因素绘制一个散点图
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 :(得分: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"))
}
答案 1 :(得分: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")
}
代码。