link_knn: k-Nearest neighbor linking

Description Usage Arguments Details Value Author(s) Examples

View source: R/link.R

Description

When a number of elements in a data are brushed, their k-nearest neighbors (based on a certain distance measure) are brushed as well.

Usage

1
link_knn(mf1, var1 = NULL, mf2 = NULL, var2 = var1, k = 10)

Arguments

var1

the variable names or column indices of the first mutaframe to be used to calculate distances

var2

(optional) variable names or column indices of the second mutaframe (by default the same as var1)

k

the number of nearest neighbors to select

mf1

the first mutaframe

mf2

(optional) the second mutaframe; default NULL means mf1 will be linked to itself

Details

A center point for the variables based on the selected rows is calculated in the first dataset, then the k nearest rows in the second dataset (if not provided, it will be the same as the first dataset) to this center are selected. Only the Euclidean distance has been implemented at the moment.

Value

Similar to categorical linking (link_cat), this function also links two mutaframes together (or one mutaframe to itself), and id's of listeners are returned.

Author(s)

Yihui Xie <http://yihui.name>

Examples

 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
### (1) linking to oneself
data(flea, package = "tourr")
qflea <- qdata(flea, color = species)
qscatter(tars1, tars2, data = qflea)

## brush the nearest 10 points around the center
id <- link_knn(qflea, c("tars1", "tars2"), k = 10)

## remove the linking
remove_link(qflea, id)


### (2) variables on the same scale
mf <- qdata(data.frame(x = rnorm(300), y = rnorm(300)), size = 3)
qscatter(x, y, data = mf)

id <- link_knn(mf, c("x", "y"), k = 20)

remove_link(mf, id)


### (3) link two datasets

mf1 <- qdata(flea, color = species)
mf2 <- qdata(subset(flea, species == "Concinna "))

qscatter(tars1, tars2, data = mf1)
qscatter(tars1, tars2, data = mf2)

id <- link_knn(mf1, c("tars1", "tars2"), mf2, c("tars1", "tars2"))

remove_link(mf1, id[1])
remove_link(mf2, id[2])

cranvas_off()

ggobi/cranvas documentation built on May 17, 2019, 3:10 a.m.