How to add legend to line graph?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to add legend to line graph?

88videos

Hi,

First off all thanks for your time.

I want to add legend in this simple example. How to do it? I need information that black line is variable1, red is variable2.

data list list
/var1 var2.
begin data.
1 1
3 1
5 3
6 4
7 5
8 3
5 5
6 7
7 3
end data.
execute.

numeric id(f8.0).
compute id=$casenum.
execute.
variable level all (scale).

GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=id var1 var2 MISSING=LISTWISE REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: id=col(source(s), name("id"))
  DATA: var1=col(source(s), name("var1"))
  DATA: var2=col(source(s), name("var2"))
  GUIDE: axis(dim(1), label("id"))
  GUIDE: axis(dim(2), label(""))
SCALE: linear (dim(2), min(0), max(12))
  ELEMENT: line(position(id*var1), missing.wings())
  ELEMENT: point(position(id*var1), color(color.black), shape(shape.circle), transparency.interior(transparency."0.1"))
   ELEMENT: line(position(id*var2), color(color.red), missing.wings())
  ELEMENT: point(position(id*var2), color(color.red), shape(shape.circle), transparency.interior(transparency."0.1"))
END GPL.


PS. By using command "GRAPH" is easy, this is default.
graph
/line(MULTIPLE)=value (var1 var2).

Wolny od wirusów. www.avast.com
===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: How to add legend to line graph?

Andy W
Thank you for the reproducible example. You need to map the aesthetics to get a legend. So in the ELEMENT lines place a reference to either a data variable or a quoted label. Then to get things the colors you want, you need to specify them in a SCALE line.

*******************************************************.
GGRAPH
  /GRAPHDATASET NAME="graphdataset" VARIABLES=id var1 var2 MISSING=LISTWISE REPORTMISSING=NO
  /GRAPHSPEC SOURCE=INLINE.
BEGIN GPL
  SOURCE: s=userSource(id("graphdataset"))
  DATA: id=col(source(s), name("id"))
  DATA: var1=col(source(s), name("var1"))
  DATA: var2=col(source(s), name("var2"))
  GUIDE: axis(dim(1), label("id"))
  GUIDE: axis(dim(2), label(""))
  SCALE: linear (dim(2), min(0), max(12))
  SCALE: cat(aesthetic(aesthetic.color.interior), map(("Var1",color.black),("Var2",color.red)))
  ELEMENT: line(position(id*var1), color("Var1"))
  ELEMENT: point(position(id*var1), color.interior("Var1"), shape(shape.circle), transparency.interior(transparency."0.1"))
  ELEMENT: line(position(id*var2), color("Var2"), missing.wings())
  ELEMENT: point(position(id*var2), color.interior("Var2"), shape(shape.circle), transparency.interior(transparency."0.1"))
END GPL.
*******************************************************.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: How to add legend to line graph?

88videos
In reply to this post by 88videos
Thanks. !!!

I didn't  know how to use map function.  

Wolny od wirusów. www.avast.com
===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD