# 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])
}
# Define weights
weights <- c(1, 0.75, 0.75, 1)
# Compute the mapping
mapping <- ara_unconstrained_l2(Z, V, weights = weights, solver = "formula")
# Select variables with labeled axis lines on ARA plot
axis_lines <- c(1, 4) # 1:"mpg", 4:"acceleration")
# Select variable used for coloring embedded points
color_variable <- 1 # "mpg"
# Draw the ARA plot
draw_ara_plot_2d_standardized(
Z,
X,
V,
mapping$P,
weights = weights,
axis_lines = axis_lines,
color_variable = color_variable
)
Run the code above in your browser using DataLab