j panton
j panton

Reputation: 232

Can you make negative values into positive values for easy comparison in a line chart in SPSS?

Let's say you want to create a line graph which plots a line for the amount of money coming in, and a line for the amount of money going out.

The variable (moneyIn) cases for money coming in is positive, like '30,000', but in this case, the amount of money being expended (moneyOut) is negative, like '-19,000'.

When I use a line graph to plot these results against eachother across a duration of time, one line is plotted way below in the negative numbers, and the other is plotted with the positive numbers, way above - so they're difficult to compare against one another.

Is there a way to change the negative values into positive ones JUST for the line graph, without computing a new variable or changing the database? I think it would essentially be a sum of (moneyOut*-1), but I don't know if this can be implemented JUST for the chart?

Upvotes: 2

Views: 1587

Answers (1)

Andy W
Andy W

Reputation: 5089

You can use the TRANS statement in inline GPL code to flip the sign. Example below.

DATA LIST FREE / In Out (2F5.0) Time (F1.0).
BEGIN DATA
1000 -1500 1
2000 -2500 2
3000 -3500 3
4000 -4500 4
END DATA.

GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=Time In Out
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: Time=col(source(s), name("Time"), unit.category())
  DATA: In=col(source(s), name("In"))
  DATA: Out=col(source(s), name("Out"))
  TRANS: OutPos = eval(Out*-1)
  GUIDE: axis(dim(1), label("Time"))
  GUIDE: axis(dim(2), label("Values"))
  SCALE: linear(dim(2), include(0))
  ELEMENT: line(position(Time*In))
  ELEMENT: line(position(Time*OutPos), color(color.blue))
END GPL.

enter image description here

Upvotes: 3

Related Questions