File: scatterplot.rkcommands.R

package info (click to toggle)
rkward 0.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 45,628 kB
  • sloc: cpp: 50,489; xml: 9,596; javascript: 6,401; python: 21; makefile: 13
file content (41 lines) | stat: -rw-r--r-- 997 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
local({
## Compute
Xvars <- rk.list(women[["weight"]],swiss[["Education"]])
Yvars <- rk.list(women[["height"]],swiss[["Catholic"]])

if (length(Xvars) != length(Yvars)) {
	stop("Unequal number of X and Y variables given")
}
# find range of X/Y values needed
Xrange <- range (c (Xvars), na.rm=TRUE)
Yrange <- range (c (Yvars), na.rm=TRUE)

type <- rep (c ('p'), length.out=length (Xvars));
col <- rep (c ('black', 'red'), length.out=length (Xvars));
cex <- rep (1, length.out=length (Xvars));
pch <- rep (1, length.out=length (Xvars));
## Print result
rk.header ("Scatterplot", parameters=list("X variables"=paste (names (Xvars), collapse=", "),
	"Y variables"=paste (names (Yvars), collapse=", ")))

rk.graph.on()

try ({
	# make frame and axes
	plot(Xrange, Yrange, type="n")
	
	# plot variables one X/Y pair at a time
	for (i in 1:length(Xvars)) {
		points (
			Xvars[[i]],
			Yvars[[i]],
			type = type[[i]],
			col = col[[i]],
			cex = cex[[i]],
			pch = pch[[i]]
		)
	}
})

rk.graph.off()
})