R wrapper for the interactive_tour function written on python
interactive_tour.Rd
R wrapper for the interactive_tour function written on python
Usage
interactive_tour(
data,
plot_objects,
feature_names = NULL,
half_range = NULL,
n_plot_cols = 2,
preselection = FALSE,
preselection_names = FALSE,
n_subsets = 3,
display_size = 5,
hover_cutoff = 10,
label_size = 15
)
Arguments
- data
the dataset you want to investigate
- plot_objects
a named list of objects you want to be displayed. Each entry requires a definition of the type of display and a specification of what should be plotted.
- feature_names
names of the features of the dataset
- half_range
factor that influences the scaling of the displayed tour plots. Small values lead to more spread out datapoints (that might not fit the plotting area), while large values lead to the data being more compact. If not provided a good estimate will be calculated and used.
- n_plot_cols
specifies the number of columns of the grid of the final display.
- preselection
a vector that specifies in which subset each datapoint should be put initially.
- preselection_names
a vector that specifies the names of the preselection subsets
- n_subsets
the total number of available subsets (up to 10).
- display_size
rough size of each subplot in inches
- hover_cutoff
number of features at which the switch from intransparent to transparent labels that can be hovered over to make them intransparent occurs
- label_size
size of the labels of the feature names of 1d and 2d tours
Examples
library(tourr)
library(reticulate)
library(lionfish)
data <- apply(flea[,1:6], 2, function(x) (x-mean(x))/sd(x))
clusters <- as.numeric(flea$species)
flea_subspecies <- unique(flea$species)
guided_tour_history <- save_history(data,
tour_path = guided_tour(holes()))
#> Value 0.993 15.8 % better - NEW BASIS
#> Value 1.080 8.8 % better - NEW BASIS
#> Value 1.097 1.6 % better - NEW BASIS
#> Value 1.119 1.9 % better - NEW BASIS
#> Value 1.121 0.2 % better - NEW BASIS
#> Value 1.125 0.3 % better - NEW BASIS
#> Value 1.132 0.6 % better - NEW BASIS
#> Value 1.144 1.1 % better - NEW BASIS
#> Value 1.147 0.2 % better - NEW BASIS
#> Value 1.150 0.3 % better - NEW BASIS
#> Value 1.151 0.1 % better - NEW BASIS
#> Value 1.153 0.1 % better - NEW BASIS
#> Value 1.155 0.2 % better - NEW BASIS
#> Value 1.156 0.1 % better - NEW BASIS
#> Value 1.160 0.4 % better - NEW BASIS
#> Value 1.163 0.3 % better - NEW BASIS
#> Value 1.164 0.0 % better
#> Value 1.166 0.2 % better - NEW BASIS
#> Value 1.191 2.1 % better - NEW BASIS
#> Value 1.200 0.8 % better - NEW BASIS
#> Value 1.211 0.9 % better - NEW BASIS
#> Value 1.220 0.7 % better - NEW BASIS
#> Value 1.241 1.7 % better - NEW BASIS
#> Value 1.248 0.6 % better - NEW BASIS
#> Value 1.254 0.4 % better - NEW BASIS
#> Value 1.259 0.4 % better - NEW BASIS
#> Value 1.266 0.5 % better - NEW BASIS
#> Value 1.270 0.3 % better - NEW BASIS
#> Value 1.272 0.2 % better - NEW BASIS
#> Value 1.274 0.1 % better - NEW BASIS
#> Value 1.274 0.0 % better
#> Value 1.275 0.1 % better
#> Value 1.275 0.1 % better
#> Value 1.275 0.1 % better
#> Value 1.274 0.0 % better
#> Value 1.274 0.0 % better
#> Value 1.274 0.0 % better
#> Value 1.274 0.1 % better
#> Value 1.275 0.1 % better
#> Value 1.274 0.0 % better
#> Value 1.274 0.0 % better
#> Value 1.274 0.0 % better
#> Value 1.275 0.1 % better
#> Value 1.275 0.1 % better - NEW BASIS
#> Value 1.276 0.0 % better
#> Value 1.277 0.1 % better - NEW BASIS
#> Value 1.277 0.0 % better
#> Value 1.277 0.0 % better
#> Value 1.277 0.0 % better
#> Value 1.277 0.0 % better
#> Value 1.277 0.0 % better
#> Value 1.277 0.0 % better
#> Value 1.277 0.0 % better
#> Value 1.277 0.0 % better
#> Value 1.277 0.1 % better
#> Value 1.277 0.0 % better
#> Value 1.277 0.0 % better
#> Value 1.277 0.1 % better
#> Value 1.277 0.0 % better
#> Value 1.277 0.0 % better
#> Value 1.277 0.0 % better
#> Value 1.278 0.1 % better
#> Value 1.277 0.0 % better
#> Value 1.277 0.0 % better
#> Value 1.277 0.0 % better
#> Value 1.277 0.0 % better
#> Value 1.277 0.0 % better
#> Value 1.277 0.0 % better
#> Value 1.277 0.0 % better
#> Value 1.277 0.0 % better
#> No better bases found after 25 tries. Giving up.
#> Final projection:
#> 0.326 -0.602
#> 0.566 0.026
#> 0.335 0.167
#> 0.511 0.355
#> 0.342 -0.538
#> 0.290 0.441
grand_tour_history_1d <- save_history(data,
tour_path = grand_tour(d=1))
half_range <- max(sqrt(rowSums(f^2)))
#> Error: object 'f' not found
feature_names <- colnames(f)
#> Error: object 'f' not found
init_env()
#> + /home/runner/.local/share/r-reticulate/pyenv/bin/pyenv update
#> + /home/runner/.local/share/r-reticulate/pyenv/bin/pyenv install --skip-existing 3.12.3
#> Error in stop_no_virtualenv_starter(version = version, python = python): Suitable Python installation for creating a venv not found.
#> Requested Python: /home/runner/.pyenv/versions/3.12.3/bin/python3.12
#> Please install Python with one of following methods:
#> - https://github.com/rstudio/python-builds/
#> - reticulate::install_python(version = '<version>')
obj1 <- list(type = "2d_tour", obj = guided_tour_history)
obj2 <- list(type = "1d_tour", obj = grand_tour_history_1d)
obj3 <- list(type = "scatter", obj = c("tars1", "tars2"))
obj4 <- list(type = "hist", obj = "head")
interactive_tour(data=data,
plot_objects=list(obj1, obj2, obj3, obj4),
feature_names=feature_names,
half_range = half_range,
n_plot_cols=2,
preselection=clusters,
preselection_names=flea_subspecies,
n_subsets = 5,
display_size=5)
#> Error: object 'feature_names' not found