#source("D:/Dropbox/02. Jobs/02. WorkMSC/01. Innovations/00. InnovationProject/function/profiling_masan.R")

5. Poultry

5.1 Poultry sensory profiling (June 11, 2020)

# Import data
library(readxl)
chicken <- read_excel("D:/Dropbox/02.Jobs/02.WorkMSC/01.Innovations/17. Poultry/Expert_Chicken_110612/Sensory profile_Chicken_11June2020.xlsx", sheet="chicken")
head(chicken)
library(tibble)
library(FactoMineR)
library(factoextra)
library(readxl)
dat.chicken <- tibble::column_to_rownames(chicken, var="product")
summary(dat.chicken)
##    [Mau]Vang     [Mau]Trang.nga  [Mau]Do.dong.deu [NQ]Do.min.mat.cat
##  Min.   :1.500   Min.   :2.000   Min.   :3.000    Min.   :1.50      
##  1st Qu.:1.625   1st Qu.:3.000   1st Qu.:3.625    1st Qu.:2.25      
##  Median :2.500   Median :3.500   Median :4.000    Median :3.00      
##  Mean   :2.667   Mean   :3.417   Mean   :3.750    Mean   :3.00      
##  3rd Qu.:3.375   3rd Qu.:4.000   3rd Qu.:4.000    3rd Qu.:3.75      
##  Max.   :4.500   Max.   :4.500   Max.   :4.000    Max.   :4.50      
##  [NQ]Do.uot.mat.cat [Mui]Thit.chin  [Mui]Khoai.tay.nau    [Mui]Mo     
##  Min.   :1.500      Min.   :2.000   Min.   :1.000      Min.   :2.000  
##  1st Qu.:3.125      1st Qu.:3.000   1st Qu.:1.625      1st Qu.:2.625  
##  Median :3.500      Median :3.250   Median :2.000      Median :3.000  
##  Mean   :3.167      Mean   :3.250   Mean   :2.083      Mean   :3.083  
##  3rd Qu.:3.500      3rd Qu.:3.875   3rd Qu.:2.750      3rd Qu.:3.750  
##  Max.   :4.000      Max.   :4.000   Max.   :3.000      Max.   :4.000  
##  [Vi]Thit.chin      [Vi]Man       [Vi]Kim.loai      [Vi]Beo     
##  Min.   :2.000   Min.   :2.000   Min.   :1.500   Min.   :2.000  
##  1st Qu.:3.125   1st Qu.:2.000   1st Qu.:2.000   1st Qu.:2.000  
##  Median :3.750   Median :2.000   Median :2.500   Median :2.250  
##  Mean   :3.583   Mean   :2.167   Mean   :2.583   Mean   :2.417  
##  3rd Qu.:4.375   3rd Qu.:2.000   3rd Qu.:3.000   3rd Qu.:2.875  
##  Max.   :4.500   Max.   :3.000   Max.   :4.000   Max.   :3.000  
##    [Vi]Umami     [HV]Ngot.thit     [HV]Umami      [CT]Do.cung   
##  Min.   :2.000   Min.   :2.000   Min.   :2.000   Min.   :1.000  
##  1st Qu.:2.625   1st Qu.:2.125   1st Qu.:3.000   1st Qu.:1.500  
##  Median :3.000   Median :2.750   Median :3.000   Median :1.750  
##  Mean   :3.000   Mean   :2.750   Mean   :3.000   Mean   :1.917  
##  3rd Qu.:3.375   3rd Qu.:3.375   3rd Qu.:3.375   3rd Qu.:2.375  
##  Max.   :4.000   Max.   :3.500   Max.   :3.500   Max.   :3.000  
##  [CT]Do.san.chac  [CT]Do.nhai    [CT]Do.mong.nuoc [CT]Do.dinh.rang
##  Min.   :1.000   Min.   :1.500   Min.   :2.000    Min.   :2.000   
##  1st Qu.:2.625   1st Qu.:2.125   1st Qu.:2.125    1st Qu.:2.250   
##  Median :3.000   Median :2.500   Median :2.500    Median :3.000   
##  Mean   :2.583   Mean   :2.667   Mean   :2.750    Mean   :2.667   
##  3rd Qu.:3.000   3rd Qu.:3.250   3rd Qu.:3.250    3rd Qu.:3.000   
##  Max.   :3.000   Max.   :4.000   Max.   :4.000    Max.   :3.000
res.pca <- PCA(dat.chicken, graph = FALSE)
fviz_pca_biplot(res.pca,  axes = c(1, 3),
                cex=.8, repel = TRUE)

Spider chart cho all users

# Vẽ spider chart
library(tibble)
library(FactoMineR)
library(factoextra)
library(plotly)

aggdata3_RD <- dat.chicken
# row.names.data.frame(aggdata3_RD)[2]

fig <- plot_ly(
  type = 'scatterpolar',
  fill = 'toself'
)
for (i in 1:nrow(aggdata3_RD)){
  fig <- fig %>%
    add_trace(
      r = as.numeric(aggdata3_RD[i,]),
      theta = as.character(colnames(aggdata3_RD)),
      name = row.names.data.frame(aggdata3_RD)[i]
    )
}
fig <- fig %>%
  layout(
    polar = list(
      radialaxis = list(
        visible = T,
        range = c(1,5)
      )
    )
  )

fig

5.2 Word association and PrefMap – 03 July

5.2.1 Word association

# require packages
library(readxl)
library(tm)
library(SnowballC)
library(wordcloud)
library(RColorBrewer)
library(SensoMineR)
library(FactoMineR)
library(wordcloud2)
library(tidyverse)
# import data
wa_poultry <- read_excel("D:/Dropbox/02.Jobs/02.WorkMSC/01.Innovations/17. Poultry/Consumer_Chicken_2506/wa.poultry.xlsx", sheet = "wa.poultry")

# plot wordcloud
set.seed(1234) # for reproducibility
wordcloud(words = wa_poultry$word, freq = wa_poultry$fre,
          min.freq = 2, max.words=30, random.order=FALSE, rot.per=0,
          colors=brewer.pal(8, "Dark2"))

5.2.2 Prefmap gà luộc

library(tibble)
library(FactoMineR)
library(factoextra)
chicken_luoc <- read_excel("D:/Dropbox/02.Jobs/02.WorkMSC/01.Innovations/17. Poultry/Consumer_Chicken_2506/25June2020_PrefMap_Luoc.xlsx",
sheet = "prefmap_luoc")
dat.chicken_luoc <- tibble::column_to_rownames(chicken_luoc, var="Sample")
res.pca.attributes <- PCA(dat.chicken_luoc[,1:19])

aggdata4_RD <- dat.chicken_luoc[,1:19]
# row.names.data.frame(aggdata3_RD)[2]

fig <- plot_ly(
  type = 'scatterpolar',
  fill = 'toself'
)
for (i in 1:nrow(aggdata4_RD)){
  fig <- fig %>%
    add_trace(
      r = as.numeric(aggdata4_RD[i,]),
      theta = as.character(colnames(aggdata4_RD)),
      name = row.names.data.frame(aggdata4_RD)[i]
    )
}
fig <- fig %>%
  layout(
    polar = list(
      radialaxis = list(
        visible = T,
        range = c(1,5)
      )
    )
  )

fig
## No scatterpolar mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## No scatterpolar mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## No scatterpolar mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## No scatterpolar mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## No scatterpolar mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## No scatterpolar mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## No scatterpolar mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## No scatterpolar mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
# hedonic mapping
hedo.luoc <- dat.chicken_luoc[,20:ncol(dat.chicken_luoc)]
res.pca.hedo <- PCA(hedo.luoc)

5.2.2 Prefmap gà chiên

chicken_chien <- read_excel("D:/Dropbox/02.Jobs/02.WorkMSC/01.Innovations/17. Poultry/Consumer_Chicken_2506/25June2020_PrefMap_Chien.xlsx",
sheet = "prefmap_chien")
dat.chicken_chien <- tibble::column_to_rownames(chicken_chien, var="Product")
res.pca.attributes.chien <- PCA(dat.chicken_chien[,1:13])

# hedonic mapping
hedo.chien <- dat.chicken_chien[,14:ncol(dat.chicken_chien)]
res.pca.hedo.chien <- PCA(hedo.chien)

5.2.3 Correlation

Đối với gà luộc

## correlation among variables
library(readxl)
library(tidyverse)
correlation_luoc <- read_excel("D:/Dropbox/02.Jobs/02.WorkMSC/01.Innovations/17. Poultry/Consumer_Chicken_2506/25June2020_PrefMap_Luoc.xlsx",
sheet = "correlation_luoc")
cor_dat_luoc <- correlation_luoc %>% select(Liking:Do.dinh.rang)
res.cor.luoc <- round(cor(cor_dat_luoc),2)
print(res.cor.luoc)
##                   Liking Mau.vang Mau.trang.nga Do.dong.deu Do.min.mat.cat
## Liking              1.00     0.28          0.04        0.04           0.28
## Mau.vang            0.28     1.00          0.00        0.20          -0.02
## Mau.trang.nga       0.04     0.00          1.00        0.14           0.03
## Do.dong.deu         0.04     0.20          0.14        1.00           0.29
## Do.min.mat.cat      0.28    -0.02          0.03        0.29           1.00
## Mui.thit.chin       0.19     0.18          0.08        0.19           0.19
## Mui.khoaitay.nau    0.11     0.12          0.17        0.03           0.17
## Mui.mo              0.04     0.38          0.02       -0.07          -0.17
## Vi.ngot.thi         0.37     0.14          0.05        0.26           0.08
## Vi.man              0.08     0.14          0.16       -0.04          -0.11
## Vi.kim.loai        -0.10     0.11          0.19       -0.10           0.01
## Vi.beo              0.13     0.33         -0.08        0.04          -0.05
## Vi.umami            0.05    -0.05         -0.06        0.09           0.09
## Huongvi.ngot.thit   0.22     0.26          0.27        0.25           0.05
## Huongvi.umami       0.08    -0.01         -0.02       -0.05           0.05
## Do.cung             0.40     0.35          0.11       -0.04          -0.01
## Do.san.chac         0.59     0.29          0.10       -0.07           0.09
## Do.nhai             0.51     0.35          0.11       -0.03           0.05
## Do.mong.nuoc        0.22     0.22         -0.08        0.10          -0.08
## Do.dinh.rang        0.30     0.19          0.17        0.20          -0.03
##                   Mui.thit.chin Mui.khoaitay.nau Mui.mo Vi.ngot.thi Vi.man
## Liking                     0.19             0.11   0.04        0.37   0.08
## Mau.vang                   0.18             0.12   0.38        0.14   0.14
## Mau.trang.nga              0.08             0.17   0.02        0.05   0.16
## Do.dong.deu                0.19             0.03  -0.07        0.26  -0.04
## Do.min.mat.cat             0.19             0.17  -0.17        0.08  -0.11
## Mui.thit.chin              1.00             0.10   0.30        0.32  -0.07
## Mui.khoaitay.nau           0.10             1.00  -0.17        0.01   0.25
## Mui.mo                     0.30            -0.17   1.00        0.25   0.23
## Vi.ngot.thi                0.32             0.01   0.25        1.00   0.23
## Vi.man                    -0.07             0.25   0.23        0.23   1.00
## Vi.kim.loai               -0.15             0.50   0.03       -0.15   0.51
## Vi.beo                     0.07            -0.02   0.50        0.07   0.37
## Vi.umami                  -0.11             0.40   0.04        0.11   0.01
## Huongvi.ngot.thit          0.16             0.25   0.23        0.62   0.28
## Huongvi.umami             -0.13             0.50   0.01        0.09  -0.01
## Do.cung                    0.07             0.07   0.10        0.21   0.17
## Do.san.chac                0.03             0.09   0.03        0.26   0.09
## Do.nhai                    0.13             0.00   0.12        0.21   0.00
## Do.mong.nuoc               0.38            -0.03   0.32        0.45   0.05
## Do.dinh.rang              -0.02             0.11  -0.04        0.24   0.08
##                   Vi.kim.loai Vi.beo Vi.umami Huongvi.ngot.thit Huongvi.umami
## Liking                  -0.10   0.13     0.05              0.22          0.08
## Mau.vang                 0.11   0.33    -0.05              0.26         -0.01
## Mau.trang.nga            0.19  -0.08    -0.06              0.27         -0.02
## Do.dong.deu             -0.10   0.04     0.09              0.25         -0.05
## Do.min.mat.cat           0.01  -0.05     0.09              0.05          0.05
## Mui.thit.chin           -0.15   0.07    -0.11              0.16         -0.13
## Mui.khoaitay.nau         0.50  -0.02     0.40              0.25          0.50
## Mui.mo                   0.03   0.50     0.04              0.23          0.01
## Vi.ngot.thi             -0.15   0.07     0.11              0.62          0.09
## Vi.man                   0.51   0.37     0.01              0.28         -0.01
## Vi.kim.loai              1.00   0.18     0.33              0.21          0.44
## Vi.beo                   0.18   1.00     0.09              0.20         -0.04
## Vi.umami                 0.33   0.09     1.00              0.42          0.86
## Huongvi.ngot.thit        0.21   0.20     0.42              1.00          0.49
## Huongvi.umami            0.44  -0.04     0.86              0.49          1.00
## Do.cung                 -0.08   0.01     0.01              0.25          0.03
## Do.san.chac             -0.14  -0.02     0.01              0.20          0.06
## Do.nhai                 -0.15   0.12    -0.06              0.13         -0.02
## Do.mong.nuoc            -0.16   0.30    -0.04              0.24         -0.07
## Do.dinh.rang            -0.01   0.24     0.09              0.28          0.02
##                   Do.cung Do.san.chac Do.nhai Do.mong.nuoc Do.dinh.rang
## Liking               0.40        0.59    0.51         0.22         0.30
## Mau.vang             0.35        0.29    0.35         0.22         0.19
## Mau.trang.nga        0.11        0.10    0.11        -0.08         0.17
## Do.dong.deu         -0.04       -0.07   -0.03         0.10         0.20
## Do.min.mat.cat      -0.01        0.09    0.05        -0.08        -0.03
## Mui.thit.chin        0.07        0.03    0.13         0.38        -0.02
## Mui.khoaitay.nau     0.07        0.09    0.00        -0.03         0.11
## Mui.mo               0.10        0.03    0.12         0.32        -0.04
## Vi.ngot.thi          0.21        0.26    0.21         0.45         0.24
## Vi.man               0.17        0.09    0.00         0.05         0.08
## Vi.kim.loai         -0.08       -0.14   -0.15        -0.16        -0.01
## Vi.beo               0.01       -0.02    0.12         0.30         0.24
## Vi.umami             0.01        0.01   -0.06        -0.04         0.09
## Huongvi.ngot.thit    0.25        0.20    0.13         0.24         0.28
## Huongvi.umami        0.03        0.06   -0.02        -0.07         0.02
## Do.cung              1.00        0.80    0.76         0.06         0.52
## Do.san.chac          0.80        1.00    0.90         0.21         0.50
## Do.nhai              0.76        0.90    1.00         0.23         0.56
## Do.mong.nuoc         0.06        0.21    0.23         1.00         0.26
## Do.dinh.rang         0.52        0.50    0.56         0.26         1.00
# library(corrplot)
# corrplot(res.cor.chien, type = "upper", order = "hclust",
#          tl.col = "black", tl.srt = 45)

Đối với gà chiên

## correlation among variables
library(tidyverse)
correlation_chien <- read_excel("D:/Dropbox/02.Jobs/02.WorkMSC/01.Innovations/17. Poultry/Consumer_Chicken_2506/25June2020_PrefMap_Chien.xlsx",
sheet = "correlation_chien")
cor_dat_chien <- correlation_chien %>% select(Liking:Do.mong.nuoc)
res.cor.chien <- round(cor(cor_dat_chien),2)
print(res.cor.chien)
##                    Liking [Mui]Thit.ga.chin [Mui]Khoi [Mui]Khet
## Liking               1.00              0.38      0.15      0.09
## [Mui]Thit.ga.chin    0.38              1.00      0.38      0.21
## [Mui]Khoi            0.15              0.38      1.00      0.82
## [Mui]Khet            0.09              0.21      0.82      1.00
## [Mui]Khoai.tay.nau  -0.08              0.07      0.26      0.28
## [Vi]Ngot.thit        0.50              0.71      0.30      0.20
## [Vi]Kim.loai         0.01              0.30      0.41      0.35
## [Vi]Umami            0.39              0.64      0.62      0.51
## [HuongVi]Ngot.thit   0.54              0.69      0.49      0.38
## [Huong.vi]Umami      0.46              0.61      0.58      0.49
## Do.dinh.rang        -0.05              0.34      0.39      0.24
## Do.cung             -0.14              0.22      0.38      0.24
## Do.dai               0.20              0.24      0.08      0.05
## Do.mong.nuoc         0.44              0.31      0.28      0.25
##                    [Mui]Khoai.tay.nau [Vi]Ngot.thit [Vi]Kim.loai [Vi]Umami
## Liking                          -0.08          0.50         0.01      0.39
## [Mui]Thit.ga.chin                0.07          0.71         0.30      0.64
## [Mui]Khoi                        0.26          0.30         0.41      0.62
## [Mui]Khet                        0.28          0.20         0.35      0.51
## [Mui]Khoai.tay.nau               1.00         -0.08         0.72      0.19
## [Vi]Ngot.thit                   -0.08          1.00         0.17      0.70
## [Vi]Kim.loai                     0.72          0.17         1.00      0.36
## [Vi]Umami                        0.19          0.70         0.36      1.00
## [HuongVi]Ngot.thit              -0.01          0.82         0.18      0.74
## [Huong.vi]Umami                  0.13          0.68         0.28      0.93
## Do.dinh.rang                     0.09          0.34         0.25      0.54
## Do.cung                          0.10          0.16         0.14      0.47
## Do.dai                          -0.17          0.40        -0.02      0.29
## Do.mong.nuoc                    -0.27          0.34        -0.06      0.27
##                    [HuongVi]Ngot.thit [Huong.vi]Umami Do.dinh.rang Do.cung
## Liking                           0.54            0.46        -0.05   -0.14
## [Mui]Thit.ga.chin                0.69            0.61         0.34    0.22
## [Mui]Khoi                        0.49            0.58         0.39    0.38
## [Mui]Khet                        0.38            0.49         0.24    0.24
## [Mui]Khoai.tay.nau              -0.01            0.13         0.09    0.10
## [Vi]Ngot.thit                    0.82            0.68         0.34    0.16
## [Vi]Kim.loai                     0.18            0.28         0.25    0.14
## [Vi]Umami                        0.74            0.93         0.54    0.47
## [HuongVi]Ngot.thit               1.00            0.82         0.20    0.20
## [Huong.vi]Umami                  0.82            1.00         0.40    0.40
## Do.dinh.rang                     0.20            0.40         1.00    0.74
## Do.cung                          0.20            0.40         0.74    1.00
## Do.dai                           0.31            0.28         0.50    0.45
## Do.mong.nuoc                     0.38            0.31        -0.16   -0.33
##                    Do.dai Do.mong.nuoc
## Liking               0.20         0.44
## [Mui]Thit.ga.chin    0.24         0.31
## [Mui]Khoi            0.08         0.28
## [Mui]Khet            0.05         0.25
## [Mui]Khoai.tay.nau  -0.17        -0.27
## [Vi]Ngot.thit        0.40         0.34
## [Vi]Kim.loai        -0.02        -0.06
## [Vi]Umami            0.29         0.27
## [HuongVi]Ngot.thit   0.31         0.38
## [Huong.vi]Umami      0.28         0.31
## Do.dinh.rang         0.50        -0.16
## Do.cung              0.45        -0.33
## Do.dai               1.00         0.07
## Do.mong.nuoc         0.07         1.00
library(corrplot)
## corrplot 0.84 loaded
corrplot(res.cor.chien, type = "upper", order = "hclust",
         tl.col = "black", tl.srt = 45)

Spider chart

Gà luộc

# Vẽ spider chart
library(tibble)
library(FactoMineR)
library(factoextra)
library(plotly)

aggdata3_RD <- dat.chicken_luoc[,1:19]
openxlsx::write.xlsx(x = aggdata3_RD,
                     file = "aggdata3_RD.xlsx")
fig <- plot_ly(
  type = 'scatterpolar',
  fill = 'toself'
)
for (i in 1:nrow(aggdata3_RD)){
  fig <- fig %>%
    add_trace(
      r = as.numeric(aggdata3_RD[i,]),
      theta = as.character(colnames(aggdata3_RD)),
      name = row.names.data.frame(aggdata3_RD)[i]
    )
}
fig <- fig %>%
  layout(
    polar = list(
      radialaxis = list(
        visible = T,
        range = c(1,5)
      )
    )
  )

fig

Gà chiên

# Vẽ spider chart
library(tibble)
library(FactoMineR)
library(factoextra)
library(plotly)

aggdata3_RD <- dat.chicken_chien[,1:13]

fig <- plot_ly(
  type = 'scatterpolar',
  fill = 'toself'
)
for (i in 1:nrow(aggdata3_RD)){
  fig <- fig %>%
    add_trace(
      r = as.numeric(aggdata3_RD[i,]),
      theta = as.character(colnames(aggdata3_RD)),
      name = row.names.data.frame(aggdata3_RD)[i]
    )
}
fig <- fig %>%
  layout(
    polar = list(
      radialaxis = list(
        visible = T,
        range = c(1,5)
      )
    )
  )

fig

Hành vi mua hàng tại siêu thị

library(readxl)
behavior_market <- read_excel("D:/Dropbox/02.Jobs/02.WorkMSC/01.Innovations/17. Poultry/Consumer_Chicken_2506/behavior_supermarket_coding.xlsx")
res.aov <- lm(diem ~ dich.mau + vet.bam + ngay.ton.tru,
              data=behavior_market)
anova(res.aov)
summary(res.aov)
## 
## Call:
## lm(formula = diem ~ dich.mau + vet.bam + ngay.ton.tru, data = behavior_market)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.6745 -2.7578 -0.3372  2.3255  6.7526 
## 
## Coefficients:
##                           Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                 3.9661     0.3606  10.997  < 2e-16 ***
## dich.maukhong.co.dich.mau   0.5104     0.3226   1.582 0.114404    
## vet.bamkhong.co.vet.bam     1.1979     0.3226   3.714 0.000235 ***
## ngay.ton.tru2ngay          -0.4453     0.3951  -1.127 0.260375    
## ngay.ton.tru3ngay          -0.7187     0.3951  -1.819 0.069651 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.161 on 379 degrees of freedom
## Multiple R-squared:  0.04933,    Adjusted R-squared:  0.0393 
## F-statistic: 4.917 on 4 and 379 DF,  p-value: 0.0007098

5.3. Mô tả GCN trên hội đồng nội bộ Nov30_2020

Bối cảnh

library(readxl)
library(tibble)
internal_desc <- read_excel("D:/Dropbox/02.Jobs/02.WorkMSC/01.Innovations/17. Poultry//InternalTest_Nov30_2020/descrip_test_Nov30.xlsx", sheet="descriptive")

internal_desc <- tibble::column_to_rownames(internal_desc, 
                                            var = "product") 
# print(internal_desc)
library(plotly)
spider_dat <- internal_desc

fig <- plotly::plot_ly(
  type = 'scatterpolar',
  fill = 'toself'
) 
for (i in 1:nrow(spider_dat)){
  fig <- fig %>%
    add_trace(
      r = as.numeric(spider_dat[i,]),
      theta = as.character(colnames(spider_dat)),
      name = row.names.data.frame(spider_dat)[i]
    )
}
fig <- fig %>%
  layout(
    polar = list(
      radialaxis = list(
        visible = T,
        range = c(1,10)
      )
    )
  )

fig 
internal_liking <- read_excel("D:/Dropbox/02.Jobs/02.WorkMSC/01.Innovations/17. Poultry/InternalTest_Nov30_2020/descrip_test_Nov30.xlsx", sheet="liking")

df <- internal_liking %>% 
  filter(product == "emoss" | product == "japfa")
#df
#+++++++++++++++++++++++++
# Function to calculate the mean and the standard deviation
  # for each group
#+++++++++++++++++++++++++
# data : a data frame
# varname : the name of a column containing the variable
  #to be summariezed
# groupnames : vector of column names to be used as
  # grouping variables
data_summary <- function(data, varname, groupnames){
  require(plyr)
  summary_func <- function(x, col){
    c(mean = mean(x[[col]], na.rm=TRUE),
      sd = sd(x[[col]], na.rm=TRUE))
  }
  data_sum<-ddply(data, groupnames, .fun=summary_func,
                  varname)
  data_sum <- rename(data_sum, c("mean" = varname))
 return(data_sum)
}
#internal_liking <- as_tibble(internal_liking)

df2 <- data_summary(df, 
                   varname = "OL_tong.the",
                   groupnames = "product")

p <- ggplot(df2, aes(x=product, y=OL_tong.the, fill=product)) + 
  geom_bar(stat="identity", color="black", 
           position=position_dodge()) +
  geom_errorbar(
    aes(ymin=OL_tong.the-sd/sqrt(nrow(df2)),
        ymax=OL_tong.the+sd/sqrt(nrow(df2))), 
    width=.2, position=position_dodge(.9)) +
  ylim(0, 5)

ggplotly(p)
res.aov <- aov(OL_tong.the ~ product, data=internal_liking)
summary(res.aov)
##             Df Sum Sq Mean Sq F value Pr(>F)
## product      2   1.25  0.6232   1.004  0.372
## Residuals   66  40.96  0.6206
TukeyHSD(res.aov) %>% plot()

5.4. Sensory Profile Farm Chicken 14 December 2020

5.5. Sensory Profile Farm Chicken 21 January 2021

5.6. Mô tả gà ta trên hội đồng nội bộ April18_2021

# import data
library(readxl)
chiki <- readxl::read_excel("D:/Dropbox/02.Jobs/02.WorkMSC/01.Innovations/17. Poultry/InternalTest_Apr18_2021/20210416-ga_luoc-rata.xlsx", 
                    sheet = "raw_data", range = "A1:AG49")
# aggregation
library(tibble)
chiki.agg <- aggregate(chiki[,4:ncol(chiki)], 
                      by = list(chiki$object_name), 
                      FUN = "mean")
colnames(chiki.agg)[1] <- "product"  
#chiki.pca <- tibble::column_to_rownames(chiki.agg, var = "product")
#print(chiki.pca)
# filter data
chiki.agg_breast <- chiki.agg[c(1,3,5,7,9,11),] 
rownames(chiki.agg_breast) <- c()
chiki.agg_breast <- tibble::column_to_rownames(chiki.agg_breast, 
                                                var = "product")

chiki.agg_thigh <- chiki.agg[c(2,4,6,8,10,12),]
rownames(chiki.agg_thigh) <- c()
chiki.agg_thigh <- tibble::column_to_rownames(chiki.agg_thigh, 
                                                var = "product")

5.6.1 Breast

library(factoextra)
res.pca_breast <- FactoMineR::PCA(chiki.agg_breast, graph = FALSE)
factoextra::fviz_pca_biplot(res.pca_breast, repel=TRUE) + 
  ggtitle("PCA map: poultry breast") +
  theme_bw()

library(plotly)

fig <- plot_ly(
  type = 'scatterpolar',
  fill = 'toself'
)
for (i in 1:nrow(chiki.agg_breast)){
  fig <- fig %>%
    add_trace(
      r = as.numeric(chiki.agg_breast[i,]),
      theta = as.character(colnames(chiki.agg_breast)),
      name = row.names.data.frame(chiki.agg_breast)[i]
    )
}
fig <- fig %>%
  layout(
    polar = list(
      radialaxis = list(
        visible = T,
        range = c(0,5)
      )
    )
  )

fig

5.6.2 Thigh

library(factoextra)
res.pca_thigh <- FactoMineR::PCA(chiki.agg_thigh, graph = FALSE)
factoextra::fviz_pca_biplot(res.pca_thigh, repel=TRUE) + 
  ggtitle("PCA map: poultry thigh") +
  theme_bw()

library(plotly)

fig <- plot_ly(
  type = 'scatterpolar',
  fill = 'toself'
)
for (i in 1:nrow(chiki.agg_thigh)){
  fig <- fig %>%
    add_trace(
      r = as.numeric(chiki.agg_thigh[i,]),
      theta = as.character(colnames(chiki.agg_thigh)),
      name = row.names.data.frame(chiki.agg_thigh)[i]
    )
}
fig <- fig %>%
  layout(
    polar = list(
      radialaxis = list(
        visible = T,
        range = c(0,5)
      )
    )
  )

fig