Script Use of Lexicometry in Sensometrics

4.3. Individual Wine Configurations

res.LexCA.Fr.list <- lapply(1:length(res.TD.Fr.list), function(i) LexCA(res.TD.Fr.list[[i]], graph=FALSE))

 

Representation for one of the judges, in this case the Catalan judge CE10.

Two possibilities:

1. Doing one CA only with CE10 from the original data baseCat.

res.TD.JCE10 <- TextData(baseCat,var.text="CE10", Fmin=1, stop.word.user=str.Cat.stopworduser)
res.LexCA.JCE10 <- LexCA(res.TD.JCE10, graph=FALSE)

 

2. Extracting the CE10 judge from the TextData object into the TextData list. CE10 has the position 8.

names(baseCat)
"CE1"  "CE2"  "CE3"  "CE4"  "CE7"  "CE8"  "CE9"  "CE10" "CE11"

res.TD.Cat.list[[8]] # Accessing by judge’s number

res.TD.Cat.list[[“CE10”]] # Accessing by judge’s name

To plot the results, we can use the plot by default (there are 12 unlabeled data points):

pJCE10 <- plot(res.LexCA.JCE10,col.doc="grey30",col.word="black",cex=0.8,title=" ",autoLab=c("yes"), graph.type = c("ggplot"))
pJCE10
Warning: ggrepel: 12 unlabeled data points (too many overlaps). Consider
increasing max.overlaps

 

To built the first factorial plane translating the words to English, we need some steps.

Building a data frame reading the coordinates names of the wines:

Dim.x <- 1
Dim.y <- 2
df.1.wines <- data.frame(res.LexCA.JCE10$row$coord[,Dim.x] ,res.LexCA.JCE10$row$coord[,Dim.y], rownames(res.LexCA.JCE10$row$coord))[,c(Dim.x,Dim.y)]
colnames(df.1.wines) <- c("x","y")
df.1.wines
                 x             y
PG05  0.000000e+00 -1.311567e-15
PG06 -1.312570e+00  2.754061e+00
EG05 -3.631635e-01 -7.875589e-01
EG06 -3.631635e-01 -7.875589e-01
PC05  2.946806e+00  7.899539e-01
PC06  3.006498e-16 -4.509747e-16
EC05 -3.631635e-01 -7.875589e-01
EC06  3.006498e-16 -4.509747e-16

Reading the words, translating to English and adding to the coordinates of the words:

df.1.words <- data.frame(res.LexCA.JCE10$col$coord[,Dim.x] ,res.LexCA.JCE10$col$coord[,Dim.y], rownames(res.LexCA.JCE10$col$coord))[,c(Dim.x, Dim.y)]
colnames(df.1.words) <- c("x","y")
df.1.words
                         x             y
brisa        -1.312570e+00  2.754061e+00
cítric       -3.631635e-01 -7.875589e-01
desequilibri  2.946806e+00  7.899539e-01
floral        2.946806e+00  7.899539e-01
fruitsec     -3.631635e-01 -7.875589e-01
fum           3.758123e-17  7.516245e-17
rodó         -3.631635e-01 -7.875589e-01
roure         3.758123e-17  7.516245e-17
tànnic        3.758123e-17  7.516245e-17
vegetal      -1.312570e+00  2.754061e+00
words.Fig1 <-rownames(df.1.words)
words.Fig1[words.Fig1 == "brisa"] <- "breeze"
words.Fig1[words.Fig1 == "cítric"] <- "citrus"
words.Fig1[words.Fig1 == "desequilibri"] <- "unbalanced"
words.Fig1[words.Fig1 == "floral"] <- "floral"
words.Fig1[words.Fig1 == "fruitsec"] <- "driedfruit"
words.Fig1[words.Fig1 == "fum"] <- "smoky"
words.Fig1[words.Fig1 == "rodó"] <- "round"
words.Fig1[words.Fig1 == "roure"] <- "oak"
words.Fig1[words.Fig1 == "tànnic"] <- "tannic"
words.Fig1[words.Fig1 == "vegetal"] <- "vegetal"
words.Fig1
"breeze"     "citrus"     "unbalanced" "floral"     "driedfruit"
 "smoky"      "round"      "oak"        "tannic"     "vegetal"  
rownames(df.1.words) <- words.Fig1

 

The coordinates of the wines and the words in English are joined together

dfWW <- rbind(df.1.wines,df.1.words)
dfWW
                       x             y
PG05        0.000000e+00 -1.311567e-15
PG06       -1.312570e+00  2.754061e+00
EG05       -3.631635e-01 -7.875589e-01
EG06       -3.631635e-01 -7.875589e-01
PC05        2.946806e+00  7.899539e-01
PC06        3.006498e-16 -4.509747e-16
EC05       -3.631635e-01 -7.875589e-01
EC06        3.006498e-16 -4.509747e-16
breeze     -1.312570e+00  2.754061e+00
citrus     -3.631635e-01 -7.875589e-01
unbalanced  2.946806e+00  7.899539e-01
floral      2.946806e+00  7.899539e-01
driedfruit -3.631635e-01 -7.875589e-01
smoky       3.758123e-17  7.516245e-17
round      -3.631635e-01 -7.875589e-01
oak         3.758123e-17  7.516245e-17
tannic      3.758123e-17  7.516245e-17
vegetal    -1.312570e+00  2.754061e+00

First, we plot the LexCA drawing without words or wines using ggrepel library to separate words and wines placed very close to each other:

library(ggrepel)
pJCE10 <-plot(res.LexCA.JCE10,col.doc="white",col.word="white",cex=0.0,title=" ",autoLab=c("no"), graph.type = c("ggplot"))
pJCE10

To add the rest of the elements in a black and white figure:

new.xlab <- paste0("Dim 1 (", round(res.LexCA.JCE10$eig[Dim.x,2],1), "%)")
new.ylab <- paste0("Dim 2 (", round(res.LexCA.JCE10$eig[Dim.y,2],1), "%)")
set.seed(9123)
Figure1 <- pJCE10 + theme_light() + xlab(new.xlab)+ ylab(new.ylab) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())+
geom_hline(yintercept=0, linetype="dashed", color = "grey")+
geom_vline(xintercept=0, linetype="dashed", color = "grey")+
geom_text_repel(aes(x=dfWW[,Dim.x] , y=dfWW[,Dim.y], label = rownames(dfWW)), max.overlaps=100,
size=7, fontface = "bold") +
theme(axis.title.x= element_text(size=17, face="bold"))+
theme(axis.title.x = element_text(vjust = -2, hjust=0.5))+
theme(axis.title.y= element_text(size=17, face="bold"))+
theme(plot.margin = grid::unit(c(t=0,r= 2,b=5, l=2), "mm"))+
theme(panel.border = element_rect(colour = "black", fill=NA, linewidth=1))+
theme(axis.text.x = element_text(size=rel(1.6)))+
theme(axis.text.y = element_text(size=rel(1.6)))
set.seed(9123)
Figure1

 

Adding different colors for the 8 wines (in red) and 10 words (in blue)

cols.Fig1 <- c(rep("#CC0000", 8), rep("blue", 10))
set.seed(9123)
Figure1 <- pJCE10 + theme_light() + xlab(new.xlab)+ ylab(new.ylab) +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank())+
geom_hline(yintercept=0, linetype="dashed", color = "grey")+
geom_vline(xintercept=0, linetype="dashed", color = "grey")+
geom_text_repel(aes(x=dfWW[,Dim.x] , y=dfWW[,Dim.y], label = rownames(dfWW)), max.overlaps=50,
size=7, fontface = "bold", colour=cols.Fig1) +
theme(axis.title.x= element_text(size=17, face="bold"))+
theme(axis.title.x = element_text(vjust = -2, hjust=0.5))+
theme(axis.title.y= element_text(size=17, face="bold"))+
theme(plot.margin = grid::unit(c(t=0,r= 2,b=5, l=2), "mm"))+
theme(panel.border = element_rect(colour = "black", fill=NA, linewidth=1))+
theme(axis.text.x = element_text(size=rel(1.6)))+
theme(axis.text.y = element_text(size=rel(1.6)))+
ggtitle("Figure 1. Individual configuration as provided by judge CE10")
set.seed(9123)
Figure1

If we want to print Figure 1 to pdf file:

graphics.off()
X11 ()
set.seed(9123)
plot (Figure1)
dev.print(pdf, 'Figure1.pdf')
dev.off ()

 

If we want to print Figure 1 to svg file:

graphics.off()
X11 ()
set.seed(9123)
library(svglite)
svglite("Figure1.svg")
plot(Figure1)
dev.off()