Luis Miguel Soto
Luis Miguel Soto

Reputation: 33

How to arrange a biplot graph of canonical discriminant functions?

Dear Stackoverflow community, I am writing this question because I have a problem when plotting an analysis I have performed on a dataset in archaeology. It turns out that I have performed a discriminant analysis by canonical functions, following an example from archaeology professor David L. Carlson, and at the moment of viewing the biplot graph of his data set the graph is shown without problems, where the number of cases associated to the centroids is observed. What happens is that when I plot my data set, the biplot graph I get does not show the number of cases associated with the centroids, I have tried several times but I can not, and I do not know if I have a problem with my data set.

The syntax of the Roman Pottery developed for professor David L. Carlson are shown below:

library(candisc)

library(archdata)

data(RBPottery)

View(RBPottery)

options(digits=3)

RBP.manova <- lm(as.matrix(RBPottery[, 4:12])~Region,RBPottery)

summary(RBP.manova)

summary(manova(RBP.manova), test="Pillai")

RBP.can <- candisc(RBP.manova)

RBP.can

summary(RBP.can)

coef(RBP.can, type="structure")

plot(RBP.can, main="Romano- British Pottery Regions - Canonical Variates")

enter image description here

The results of my analysis are shown below:

Vertientes <-c("Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Oeste", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este", "Este")
Cluster <-c("Sitios_pequeños_cluster_2", "Sitios_medianos_cluster_2", "Sitios_medianos_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_grandes_cluster_1", "Sitios_grandes_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_medianos_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_medianos_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_medianos_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_medianos_cluster_1", "Sitios_pequeños_cluster_3", "Sitios_grandes_cluster_3", "Sitios_pequeños_cluster_3", "Sitios_pequeños_cluster_3", "Sitios_pequeños_cluster_3", "Sitios_pequeños_cluster_3", "Sitios_pequeños_cluster_2", "Sitios_pequeños_cluster_2", "Sitios_pequeños_cluster_2", "Sitios_pequeños_cluster_2", "Sitios_pequeños_cluster_2", "Sitios_grandes_cluster_2", "Sitios_pequeños_cluster_2", "Sitios_grandes_cluster_2", "Sitios_grandes_cluster_2", "Sitios_medianos_cluster_2", "Sitios_medianos_cluster_2", "Sitios_pequeños_cluster_2", "Sitios_pequeños_cluster_2", "Sitios_pequeños_cluster_2", "Sitios_pequeños_cluster_2", "Sitios_medianos_cluster_2", "Sitios_grandes_cluster_2", "Sitios_medianos_cluster_2", "Sitios_medianos_cluster_2", "Sitios_grandes_cluster_2", "Sitios_pequeños_cluster_2", "Sitios_pequeños_cluster_2", "Sitios_pequeños_cluster_2", "Sitios_medianos_cluster_2", "Sitios_pequeños_cluster_2", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_2", "Sitios_pequeños_cluster_2", "Sitios_medianos_cluster_2", "Sitios_pequeños_cluster_1", "Sitios_pequeños_cluster_1", "Sitios_medianos_cluster_1", "Sitios_grandes_cluster_1", "Sitios_pequeños_cluster_2", "Sitios_pequeños_cluster_3", "Sitios_pequeños_cluster_3", "Sitios_pequeños_cluster_3", "Sitios_medianos_cluster_3", "Sitios_pequeños_cluster_3", "Sitios_pequeños_cluster_3", "Sitios_grandes_cluster_3", "Sitios_medianos_cluster_3", "Sitios_pequeños_cluster_3", "Sitios_pequeños_cluster_3", "Sitios_pequeños_cluster_3", "Sitios_pequeños_cluster_3", "Sitios_pequeños_cluster_3", "Sitios_pequeños_cluster_3", "Sitios_medianos_cluster_3", "Sitios_pequeños_cluster_3", "Sitios_medianos_cluster_3", "Sitios_pequeños_cluster_3", "Sitios_medianos_cluster_3")
Tamaños <-c("Sitios_pequeños", "Sitios_medianos", "Sitios_medianos", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitio_grande", "Sitio_grande", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_medianos", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_medianos", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_medianos", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_medianos", "Sitios_pequeños", "Sitio_grande", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitio_grande", "Sitios_pequeños", "Sitio_grande", "Sitio_grande", "Sitios_medianos", "Sitios_medianos", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_medianos", "Sitio_grande", "Sitios_medianos", "Sitios_medianos", "Sitio_grande", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_medianos", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_medianos", "Sitios_pequeños", "Sitios_pequeños", "Sitios_medianos", "Sitio_grande", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_medianos", "Sitios_pequeños", "Sitios_pequeños", "Sitio_grande", "Sitios_medianos", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_pequeños", "Sitios_medianos", "Sitios_pequeños", "Sitios_medianos", "Sitios_pequeños", "Sitios_medianos")
Tamaño <-c(1954, 5721, 9042, 1954, 1954, 2889, 10825, 10948, 4864, 1954, 1954, 8847, 3907, 1954, 1954, 1954, 1954, 1954, 5372, 1954, 1954, 1954, 1954, 1954, 1954, 1954, 1954, 1954, 1954, 3606, 1954, 1954, 1954, 6671, 1954, 1954, 1954, 1954, 1954, 1954, 5205, 3907, 22651, 1954, 1954, 1954, 1954, 1954, 1954, 3068, 3336, 3321, 11021, 4081, 20865, 14330, 5317, 5759, 1954, 1954, 1954, 1954, 9331, 19103, 5323, 7320, 11532, 3728, 1954, 3244, 7978, 1954, 1954, 1954, 1954, 8496, 1954, 4079, 5674, 10200, 2744, 1954, 1954, 1954, 6736, 1954, 4489, 14801, 8670, 1954, 3309, 1954, 3262, 3723, 1954, 6966, 2921, 5257, 2717, 6202)
Altura <-c(708, 652, 910, 916, 1048, 1082, 1122, 1206, 859, 1113, 1352, 1388, 561, 931, 928, 950, 958, 996, 992, 1056, 964, 772, 807, 864, 889, 911, 1176, 536, 739, 777, 806, 953, 615, 648, 686, 943, 1060, 1088, 1164, 989, 1062, 652, 677, 741, 810, 748, 568, 649, 840, 945, 954, 1005, 1061, 1107, 1131, 1193, 1429, 861, 957, 1022, 1036, 1125, 1251, 606, 663, 854, 897, 950, 1067, 1166, 1211, 1252, 611, 1002, 1056, 1110, 536, 592, 578, 619, 1050, 540, 692, 1054, 559, 842, 1113, 1106, 937, 1030, 1068, 1016, 1065, 1141, 416, 528, 550, 723, 619, 18.8)
Pendiente <-c(23, 15, 35, 30, 40, 19, 38, 27, 33, 33, 22, 30, 9, 16, 24, 9, 23, 31, 24, 20, 9, 15, 33, 28, 36, 26, 25, 9, 24, 35, 20, 12, 25, 20, 9, 12, 26, 18, 23, 2, 20, 22, 23, 31, 23, 5, 12, 16, 2, 35, 25, 31, 30, 20, 36, 26, 19, 31, 26, 18, 15, 24, 7, 16, 29, 26, 21, 31, 32, 25, 13, 10, 14, 29, 27, 26, 5, 9, 11, 19, 28, 24, 18, 16, 20, 25, 11, 44, 11, 30, 24, 22, 35, 11, 30, 23, 9, 20, 25, 1)
Tiestos <-c(4, 37, 22, 71, 10, 1, 2, 57, 1, 5, 19, 7, 98, 46, 20, 71, 10, 13, 74, 137, 13, 1, 34, 4, 14, 14, 86, 2, 55, 43, 39, 12, 8, 13, 34, 3, 9, 15, 4, 6, 26, 32, 10, 1, 10, 4, 5, 116, 182, 34, 202, 43, 11, 15, 67, 7, 2, 145, 38, 3, 8, 11, 342, 43, 10, 42, 8, 6, 14, 3, 4, 7, 199, 7, 18, 67, 13, 51, 46, 104, 46, 74, 11, 15, 10, 55, 263, 57, 3, 10, 5, 4, 16, 3, 30, 30, 36, 124, 31, 120)
Vasijas <-c(0, 6, 1, 9, 2, 0, 0, 1, 0, 0, 1, 0, 29, 6, 2, 2, 1, 1, 4, 12, 0, 1, 1, 0, 3, 1, 9, 1, 2, 4, 3, 0, 1, 2, 5, 0, 1, 4, 0, 1, 3, 1, 1, 0, 2, 0, 0, 13, 68, 11, 67, 14, 4, 2, 43, 0, 0, 35, 9, 0, 7, 2, 87, 14, 1, 8, 0, 1, 1, 0, 0, 0, 42, 0, 0, 0, 4, 2, 8, 6, 2, 6, 0, 8, 2, 3, 32, 3, 0, 1, 1, 0, 1, 0, 13, 3, 0, 19, 1, 13)
Decorados <-c(0, 3, 0, 0, 2, 0, 0, 0, 2, 0, 1, 0, 10, 1, 0, 2, 1, 2, 4, 3, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 16, 46, 11, 55, 7, 1, 1, 10, 0, 0, 7, 1, 1, 2, 0, 52, 5, 0, 1, 4, 0, 1, 2, 0, 0, 29, 0, 0, 0, 0, 0, 1, 3, 2, 2, 2, 0, 0, 0, 100, 6, 0, 2, 0, 0, 8, 0, 19, 6, 0, 6, 2, 12)

Congo_DMA_2 <- data.frame(Vertientes, Cluster, Tamaños, Tamaño, Altura, Pendiente, Tiestos, Vasijas, Decorados)

View(Congo_DMA_2)

Congo_DMA_2

str(Congo_DMA_2)

options(digits=3)

Congo.manova <- lm(as.matrix(Congo_DMA_2[, 4:9])~Cluster,Congo_DMA_2)

summary(Congo.manova)

library(candisc)

Congo.can <- candisc(Congo.manova)

Congo.can

summary(Congo.can)

coef(Congo.can, type="structure")

plot(Congo.can, main="Juego de datos del Congo para análsis discriminante canónico de las variables sitios y tamaños")

enter image description here

Thank you very much for your attention, being a new archaeologist in the world of programming I apologize if the way of presenting this question is incorrect. Best regards to all of you.

Upvotes: 3

Views: 273

Answers (1)

dcarlson
dcarlson

Reputation: 11056

The problem is that Congo_DMA_2$Cluster must be a factor, not a character vector. Older versions of R made this conversion automatically when creating a data frame, but the current versions do not. Just add the following line to your code after creating Congo_DMA_2:

Congo_DMA_2 <- data.frame(Vertientes, Cluster, Tamaños, Tamaño, Altura, Pendiente, Tiestos, Vasijas, Decorados)   # Your code
Congo_DMA_2$Cluster <- factor(Congo_DMA_2$Cluster)  # Added line

Then the plot will include the individual points.

Plot

Upvotes: 1

Related Questions