library(tidyverse) library(patchwork) urlfile = “https://github.com//zia207/r-colab/raw/main/Data/USA/gp_soil_data.csv” mf <- read_csv(url(urlfile)) X <- mf %>% dplyr::select(DEM, Aspect, Slope, TPI) %>% scale() Y <- mf %>% dplyr::select(MAT, MAP, NDVI) %>% scale() cc <- cancor(X, Y) str(cc) print(cc) cc\(cor CC1_X <- as.matrix(X) %*% cc\)xcoef[, 1] CC1_Y <- as.matrix(Y) %% cc\(ycoef[, 1] CC2_X <- as.matrix(X) %*% cc\)xcoef[, 2] CC2_Y <- as.matrix(Y) %% cc$ycoef[, 2] cca_df <- mf %>% mutate(CC1_X = CC1_X, CC1_Y = CC1_Y, CC2_X = CC2_X, CC2_Y = CC2_Y) %>% glimpse() cca_df %>% ggplot(aes(x=CC1_X, y=CC1_Y, color=NLCD)) + geom_point() p1 <- cca_df %>% ggplot(aes(x=NLCD, y=CC1_X, color=NLCD)) + geom_boxplot(width=0.5) + geom_jitter(width=0.15) + theme(legend.position=“none”) + ggtitle(“First Canonical Variate of X vs NLCD”)

p2 <- cca_df %>% ggplot(aes(x=NLCD, y=CC1_Y, color=NLCD)) + geom_boxplot(width=0.5) + geom_jitter(width=0.15) + theme(legend.position=“none”) + ggtitle(“First Canonical Variate of Y vs NLCD”) p1 + p2