# Define subset of (numerical) variables
# 1:"mpg", 4:"horsepower", 5:"weight", 6:"acceleration"
selected_variables <- c(1, 4, 5, 6)
n <- length(selected_variables)
# Retain only selected variables and rename dataset as X
X <- auto_mpg[, selected_variables] # Select a subset of variables
# Remove rows with missing values from X
N <- nrow(X)
rows_to_delete <- NULL
for (i in 1:N) {
if (sum(is.na(X[i, ])) > 0) {
rows_to_delete <- c(rows_to_delete, -i)
}
}
X <- X[rows_to_delete, ]
# Convert X to matrix
X <- apply(as.matrix.noquote(X), 2, as.numeric)
# Standardize data
Z <- scale(X)
# Define axis vectors (2-dimensional in this example)
r <- c(0.8, 1, 1.2, 1)
theta <- c(225, 100, 315, 80) * 2 * pi / 360
V <- pracma::zeros(n, 2)
for (i in 1:n) {
V[i,1] <- r[i] * cos(theta[i])
V[i,2] <- r[i] * sin(theta[i])
}
# Select variable for exact estimates, and use it for coloring the embedded
# points
variable <- sample(1:n, 1)
# Compute the mapping
mapping <- ara_ordered_linf(
Z,
V,
variable = variable,
solver = "clarabel"
)
# Select variables with labeled axis lines on ARA plot
axis_lines <- variable
# Draw the ARA plot
draw_ara_plot_2d_standardized(
Z,
X,
V,
mapping$P,
axis_lines = axis_lines,
color_variable = variable
)
Run the code above in your browser using DataLab