为spss中的每个案例创建绘图

时间:2014-08-01 17:43:01

标签: plot spss

基于此网站http://www-01.ibm.com/support/docview.wss?uid=swg21476602 我想用6个变量在SPSS中创建一个蜘蛛图。但是,我想从我的数据集中为每一行或大小写创建它。

示例:

id  var1  var2  var3  var4  var5  var6
1    4     4    3      4     2      1
2    3     4    2      4     4      4
3    4     1    3      1     4      4
4    1     1    2      4     1      4
5    4     3    4      1     2      2

输出应为5个名为id的蜘蛛图表。

感谢任何帮助:)

1 个答案:

答案 0 :(得分:0)

最简单的方法是不要使用平行坐标,只需重新整形数据,以便Var1 TO Var6位于同一列中。

DATA LIST FREE / ID Var1 TO Var6.
BEGIN DATA
1    4     4    3      4     2      1
2    3     4    2      4     4      4
3    4     1    3      1     4      4
4    1     1    2      4     1      4
5    4     3    4      1     2      2
END DATA.

*Reshape and make graph - much easier.
VARSTOCASES /MAKE Var FROM Var1 TO Var6 /INDEX VarID (Var).
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=VarID Var ID
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: VarID=col(source(s), name("VarID"), unit.category())
  DATA: ID=col(source(s), name("ID"), unit.category())
  DATA: Var=col(source(s), name("Var"))
  COORD: polar(dim(1,2))
  GUIDE: axis(dim(1), label("VarID"))
  GUIDE: axis(dim(2), label("Var"))
  ELEMENT: line(position(VarID*Var), split(ID), color(ID), closed(), 
           preserveStraightLines())
END GPL.

要制作这些单独的图表(因此每个ID都有自己的图表,并且它们不会叠加在同一个图表上),您可以使用小的倍数:

GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=VarID Var ID
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: VarID=col(source(s), name("VarID"), unit.category())
  DATA: ID=col(source(s), name("ID"), unit.category())
  DATA: Var=col(source(s), name("Var"))
  COORD: polar(dim(1,2), wrap())
  GUIDE: axis(dim(1), label("VarID"))
  GUIDE: axis(dim(2), label("Var"))
  ELEMENT: line(position(VarID*Var*ID), closed(), preserveStraightLines())
END GPL.

或者您可以使用SPLIT FILE

SPLIT FILE BY ID.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=VarID Var ID
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: VarID=col(source(s), name("VarID"), unit.category())
  DATA: ID=col(source(s), name("ID"), unit.category())
  DATA: Var=col(source(s), name("Var"))
  COORD: polar(dim(1,2))
  GUIDE: axis(dim(1), label("VarID"))
  GUIDE: axis(dim(2), label("Var"))
  ELEMENT: line(position(VarID*Var), closed(), preserveStraightLines())
END GPL.
SPLIT FILE OFF.

使用原始数据,可以使用平行坐标,与您列出的给定技术说明几乎相同,但是格式化所有轴更加烦人。示例如下。

DATA LIST FREE / ID Var1 TO Var6.
BEGIN DATA
1    4     4    3      4     2      1
2    3     4    2      4     4      4
3    4     1    3      1     4      4
4    1     1    2      4     1      4
5    4     3    4      1     2      2
END DATA.
DATASET NAME Temp.
EXECUTE.

*Using parrallel coordinate plot.
FORMATS ID Var1 TO Var6 (F1.0).
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=ID Var1 Var2 Var3 Var4 Var5 Var6
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: ID=col(source(s), name("ID"), unit.category())
  DATA: Var1=col(source(s), name("Var1"))
  DATA: Var2=col(source(s), name("Var2"))
  DATA: Var3=col(source(s), name("Var3"))
  DATA: Var4=col(source(s), name("Var4"))
  DATA: Var5=col(source(s), name("Var5"))
  DATA: Var6=col(source(s), name("Var6"))
  COORD: polar(parallel())
  GUIDE: axis(dim(1), label("Var1"), delta(1), start(1))
  GUIDE: axis(dim(2), label("Var2"), delta(1), start(1))
  GUIDE: axis(dim(3), label("Var3"), delta(1), start(1))
  GUIDE: axis(dim(4), label("Var4"), delta(1), start(1))
  GUIDE: axis(dim(5), label("Var5"), delta(1), start(1))
  GUIDE: axis(dim(6), label("Var6"), delta(1), start(1))
  SCALE: linear(dim(1), min(0), max(4.2))
  SCALE: linear(dim(2), min(0), max(4.2))
  SCALE: linear(dim(3), min(0), max(4.2))
  SCALE: linear(dim(4), min(0), max(4.2))
  SCALE: linear(dim(5), min(0), max(4.2))
  SCALE: linear(dim(6), min(0), max(4.2))
  ELEMENT: line(position(Var1*Var2*Var3*Var4*Var5*Var6), split(ID), closed(),
           preserveStraightLines())
END GPL.

对于这个示例数据,它们都产生相当丑陋的图表 - 并且没有明显需要给出的极坐标。为了让每个人都拥有自己的图表,上面显示的小倍数不会直接起作用,但SPLIT FILE方法会有效。


对于添加所有观察的平均值的最新请求,这是一个潜在的工作流程:

  • 使用AGGREGATE为所有变量的平均值添加6列,例如AGGREGATE OUTFILE=* MODE=ADDVARIABLES /BREAK /VM1 TO VM6 = MEAN(V1 TO V6).
  • 当重塑形成两个新变量时,例如VARSTOCASES /MAKE Var FROM Var1 TO Var6 /MAKE Var2 FROM VM1 TO VM6 /INDEX VarID
  • 在GGRAPH代码中,将Var2添加到VARIABLES命令
  • 对于内嵌GPL代码,为DATA添加Var2行,并在第二行ELEMENT显示均值。